/* DISPLAY APROVED REJCTED ******************************************** * - Just fetches a template saying thank you /// approved, rejected. **********************************************************************/ function displayVoteResult( $params, $smarty ){ $smarty->assign("RESULT", $params['sub_action'] ); /* Fetch template */ $smarty->display("moderation/vote_result.tpl"); die(); } } ?> $sql = "SELECT * FROM change_record WHERE change_record_id = $change_record_id "; $res = sql_getrow( $sql, DB_IE_STAGE ); $form_id = $res['form_id']; /* Switch case on form_type */ switch($form_id){ case US_PERSON: $sql = "UPDATE person "; break; case US_PRODUCT: $sql = "UPDATE product "; break; case US_COMPANY: $sql = "UPDATE company "; break; case US_BLURB: $ref_type_id = $res['ref_type_id']; switch($ref_id){ case REF_TYPE_PERSON: $sql = "UPDATE person "; break; case REF_TYPE_PRODUCT: $sql = "UPDATE product "; break; case REF_TYPE_COMPANY: $sql = "UPDATE company "; break; } break; } /* Reject in the appropriate table */ $sql .= "SET record_state_id = $record_state_id WHERE change_record_id = $change_record_id "; sql_execute( $sql, DB_IE_STAGE ); return; } /* PROCESS USER VOTE ************************************************** * - Processes a user vote. **********************************************************************/ function processUserVote( $change_record_id, $user_id, $user_score ){ /* First check to see if the user has already voted on this chg_rec */ $sql = "SELECT user_id FROM change_record_community_scores WHERE user_id = $user_id AND change_record_id = $change_record_id "; $res = sql_getrow( $sql, DB_IE_STAGE ); /* If not, insert a new rec into the COUNT table */ if(!$res){ /* Insert rec into COUNT table */ $sql = "INSERT INTO change_record_community_scores(change_record_id, score, user_id, score_date) VALUES($change_record_id, $user_score, $user_id, now()) "; sql_execute( $sql, DB_IE_STAGE ); /* Get the sum of scores for this chng_rec */ $sql = "SELECT sum(score) sum_score FROM change_record_community_scores WHERE change_record_id = $change_record_id "; $res = sql_getrow( $sql, DB_IE_STAGE ); $sum_score = $res['sum_score']; /* Update the score of the rec in the CHG_REC table */ $sql = "UPDATE change_record SET community_vote_count = community_vote_count + 1, community_score = $sum_score/community_vote_count WHERE change_record_id = $change_record_id "; sql_execute( $sql, DB_IE_STAGE ); /* Get the count of votes and the average score for the rec */ $sql = "SELECT community_vote_count, community_score FROM change_record WHERE change_record_id = $change_record_id "; $res = sql_getrow( $sql, DB_IE_STAGE ); $community_score = $res['community_score']; $community_vote_count = $res['community_vote_count']; /* If approval criteria met -> set rec to prod */ if( $community_vote_count > 3 && $community_score > 6 ){ $USPushToProd = createDataObject( "UserSubmissionPushToProd" ); /* Moderated is true -> this rec was voted on and moderated */ $moderated = true; /* Push the record to production */ $USPushToProd->pushToProduction( $change_record_id, $moderated ); return "approved"; } /* If rejection criteria met -> reject rec */ if( $community_vote_count > 3 && $community_score < 3 ){ $this->rejectRecord( $change_record_id, $record_state_id ); return "rejected"; } } return; } /* HELPER FUNCTIONS ##################################################*/ function getRefTypeName( $ref_type_id ){ $ref_type_name = ""; switch ($ref_type_id){ case REF_TYPE_PERSON: $ref_type_name = "Person"; break; case REF_TYPE_PRODUCT: $ref_type_name = "Product"; break; case REF_TYPE_COMPANY: $ref_type_name = "Company"; break; } return $ref_type_name; } function getChangeTypeName( $change_type ){ $change_type_name = ""; switch ($change_type){ case CHANGE_TYPE_ADD: $change_type_name = "Add"; break; case CHANGE_TYPE_EDIT: $change_type_name = "Edit"; break; case CHANGE_TYPE_DELETE: $change_type_name = "Delete"; break; } return $change_type_name; } // checks to see if the user is the current editor for the current product/person function isUserAnEditor($change_record_id, $user_id, $change_type){ $sql = "SELECT * FROM change_record WHERE change_record_id = $change_record_id "; echo $sql."
"; $res = sql_getrow( $sql, DB_IE_STAGE ); $ref_id = $res['ref_id']; $ref_type_id = $res['ref_type_id']; if( $ref_type_id == REF_TYPE_PRODUCT){ // match on the parent_id if($change_type == CHANGE_TYPE_EDIT){ $sql = "SELECT p.editor_id FROM product p, industry_stage.product pp WHERE p.editor_id = $user_id AND pp.product_id = $ref_id AND pp.parent_id = p.product_id "; echo $sql."
"; $results = sql_getrow( $sql, DB_IE_PROD ); if(!empty($results)) return true; } // match on the real_id else{ $sql = "SELECT editor_id FROM product WHERE editor_id = $user_id AND product_id = $ref_id "; $results = sql_getall( $sql, DB_IE_PROD ); if(!empty($results)) return true; } } else if( $ref_type_id == REF_TYPE_PERSON){ // match on the parent_id if($change_type == CHANGE_TYPE_EDIT){ $sql = "SELECT p.editor_id FROM person p, industry_stage.person pp WHERE p.editor_id = $user_id AND pp.person_id = $ref_id AND pp.parent_id = p.person_id "; echo $sql."
"; $results = sql_getrow( $sql, DB_IE_PROD ); if(!empty($results)) return true; } // match on the real_id else{ $sql = "SELECT editor_id FROM person WHERE editor_id = $user_id AND person_id = $ref_id "; $results = sql_getall( $sql, DB_IE_PROD ); if(!empty($results)) return true; } } die; return false; } } ?>