* @version $Id$ * @access public * @license http://opensource.org/licenses/gpl-3.0.html * Workgroup Forum Management */ class workshop_com { /* @param * */ var $TDB_COM = T_WORK_COM; // nom de la table. var $ID; var $SUBJECT; var $BODY; var $PARENT; var $USER_ID; var $WORKSHOP_ID; var $DATE_CREA; var $LAST_MODIFY; var $STATUT; protected $dispatcher = null; public function __construct() { $this->dispatcher = $GLOBALS['dispatcher']; } public function __call($method, $arguments) { $event = $this->dispatcher->notifyUntil(new sfEvent($this, 'workshop_com.extensible_function', array( 'method' => $method, 'arguments' => $arguments ))); if (!$event->isProcessed()) { throw new Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method)); } return $event->getReturnValue(); } /** * workshop_com::isComAuthor() * Vérifie si un utilisateur donné et l'auteur d'un message * * @access public * @param integer $message_id contient l'identifiant du message * @param integer $message_id contient l'identifiant du supposé auteur * @return boolean true * si verifié true, sinon false */ function isComAuthor($message_id, $user_id, $sql_object) { $q_son = "SELECT workcom_id FROM " . $this->TDB_COM . " WHERE workcom_statut <> 'E' AND workcom_id=$message_id AND workcom_user_id=$user_id"; $r = $sql_object->DBSelect($q_son); if (isset($r[0]['workcom_id'])) return true; else return false; } /** * workshop_com::CheckDataIntegrity() * Vérification intégrité des données * * @access public * @param array $table contient les composants d'une discussion * @return boolean true * si verifié, sinon string 'message d'erreur' */ function CheckDataIntegrity($table, $sql_object) { // Filter data event + return value $r = $this->dispatcher->filter(new sfEvent($this, 'workshopcom.before_datacheck', array('data' => $table)), $table); $table = $r->getReturnValue(); if (strlen($table[0]) < 3) return _t('workshop','com_no_subject'); if (strlen($table[1]) < 10) return _t('workshop','com_no_body'); // we check if user id is numeric and belongs to the workgroup // test to prevent SQL error if provided ID is wrong (can happen with TextBoxList js plugin if(!is_numeric($table[3])) return _t('workshop','author_not_allowed'); $q = "SELECT * FROM l21_j_work_users where jwu_user_id = ".$table[3]." AND jwu_workshop_id =".$table[4].";"; $r = $sql_object->DBSelect($q); if(!isset($r[0]['jwu_id'])) return _t('workshop','author_not_allowed'); // Notify the beginning of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.after_datacheck', array('data' => $table))); return true; } /** * * @param integer $id * @param SQL object $sql_object * @return boolean */ public function incrementViewsCounter($id, $sql_object) { if(!is_numeric($id)) return false; $q = 'UPDATE '.$this->TDB_COM.' SET workcom_viewed = workcom_viewed + 1, workcom_last_modify = workcom_last_modify WHERE workcom_id='.$id; $r = $sql_object->DBQuery($q); // Notify the end of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.increment_views', array('id' => $id))); return true; } /** * workshop_com::AddCom() * Ajout d'une nouvelle discussion * * @access public * @param array $table_com : contient les composants d'une discussion * @param object $sql_object * @return integer $last_id */ function AddCom($table_com, $sql_object) { global $l21auth; // Filter data event + return value $r = $this->dispatcher->filter(new sfEvent($this, 'workshopcom.before_add', array('data' => $table_com)), $table_com); $table_com = $r->getReturnValue(); // image 64 encoded conversion if enabled before escaping content $table_com[1] = convertBase64Images($table_com[1], 'forum-'); $table_com=$sql_object->DBescape($table_com); $this->SUBJECT = strip_input(trim($table_com[0])); $this->BODY = strip_input(trim($table_com[1])); if ($table_com[2] != '') { $this->PARENT_ID = $table_com[2]; } else $this->PARENT_ID = 0; $this->USER_ID = $table_com[3]; $this->WORKSHOP_ID = $table_com[4]; $this->STATUT = "P"; if ($this->PARENT_ID == 0) { $q = "INSERT INTO " . $this->TDB_COM . " (workcom_subject, workcom_body, workcom_parent, workcom_user_id, workcom_workshop_id, workcom_statut, workcom_date_crea, workcom_last_modify ) " . "VALUES('" . $this->SUBJECT . "', '" . $this->BODY . "', " . $this->PARENT_ID . ", " . $this->USER_ID . ", " . $this->WORKSHOP_ID . ", '" . $this->STATUT . "', NOW(), NOW());"; $last_id = $sql_object->DBInsert ($q, 1); } else { $q_root = "UPDATE " . $this->TDB_COM . " SET workcom_last_modify=NOW() WHERE workcom_id=" . $this->PARENT_ID . ";"; $result_root = $sql_object->DBQuery($q_root); $q = "INSERT INTO " . $this->TDB_COM . " (workcom_subject, workcom_body, workcom_parent, workcom_user_id, workcom_workshop_id, workcom_statut, workcom_date_crea, workcom_last_modify ) " . "VALUES('" . $this->SUBJECT . "', '" . $this->BODY . "', " . $this->PARENT_ID . ", " . $this->USER_ID . ", " . $this->WORKSHOP_ID . ", '" . $this->STATUT . "', NOW(), NOW());"; $last_id = $sql_object->DBInsert ($q, 1); } // we log delete action if(is_numeric($last_id)) logfile(LOG_MAINFILE, array('[action] add workgroup thread', 'ID='.$last_id, 'parent_ID='.$this->PARENT_ID, 'by_id='.$l21auth->GetSessionElement('id'), 'by_login='.$l21auth->GetSessionElement('login'))); // Notify the end of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.after_add', array('data' => $table_com, 'id' => $last_id))); return $last_id; } /** * workshop_com::DeleteCom() * suppression d'un message * * @access public * @param int $com_id identifiant du message * @param int $parent_id identifiant du parent * @param object $sql_object * @return bool $result */ function DeleteCom($ID, $com_id, $parent_id, $sql_object) { global $l21auth; // Notify the beginning of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.delete', array('id' => $ID, 'comid' => $com_id, 'parentid' => $parent_id))); if (is_numeric($ID)) { $this->ID = $ID; } else return false; // we log delete action logfile(LOG_MAINFILE, array('[action] delete workgroup thread', 'ID='.$ID, 'com_ID='.$com_id, 'parent_ID='.$parent_id, 'by_id='.$l21auth->GetSessionElement('id'), 'by_login='.$l21auth->GetSessionElement('login'))); if ($parent_id == 0) { $q_son = "SELECT workcom_id FROM " . $this->TDB_COM . " WHERE workcom_statut <> 'E' AND workcom_parent=$com_id AND workcom_workshop_id=$ID"; $result_son = $sql_object->DBSelect($q_son); if ($result_son <> 0) { $q = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;"; $result = $sql_object->DBQuery ($q); for($i = 0; $i < count($result_son); $i++) { $q_son_e = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=" . $result_son[$i]['workcom_id'] . ";"; $result_son_e = $sql_object->DBQuery ($q_son_e); } return $result; } else { $q = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;"; $result = $sql_object->DBQuery ($q); return $result; } } else { $q = "UPDATE " . $this->TDB_COM . " SET workcom_statut='E' WHERE workcom_id=$com_id;"; $result = $sql_object->DBQuery ($q); return $result; } } /** * workshop_com::LockCom() * vérouillage d'un message * * @access public * @param int $ID identifiant du workshop * @param int $com_id identifiant du message * @param int $parent_id identifiant du message parent * @param int $lock * @param object $sql_object * @return bool $result */ function LockCom($ID, $com_id, $parent_id, $lock, $sql_object) { global $l21auth; // Notify the beginning of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.lock', array('id' => $ID, 'comid' => $com_id, 'parentid' => $parent_id, 'lock' => $lock))); if ($lock == 0) $statut = 'C'; else $statut = 'P'; if (is_numeric($ID)) { $this->ID = $ID; } else return false; logfile(LOG_MAINFILE, array('[action] lock / unlock workgroup thread', 'ID='.$ID, 'com_ID='.$com_id, 'parent_ID='.$parent_id, 'by_id='.$l21auth->GetSessionElement('id'), 'by_login='.$l21auth->GetSessionElement('login'))); if ($parent_id == 0) { $q_son = "SELECT workcom_id FROM " . $this->TDB_COM . " WHERE workcom_statut <> 'E' AND workcom_parent=$com_id AND workcom_workshop_id=$ID"; $result_son = $sql_object->DBSelect($q_son); if ($result_son <> 0) { $q = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=$com_id;"; $result = $sql_object->DBQuery ($q); for($i = 0; $i < count($result_son); $i++) { $q_son_e = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=" . $result_son[$i]['workcom_id'] . ";"; $result_son_e = $sql_object->DBQuery ($q_son_e); } return $result; } else { $q = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=$com_id;"; $result = $sql_object->DBQuery ($q); return $result; } } else { $q = "UPDATE " . $this->TDB_COM . " SET workcom_statut='" . $statut . "' WHERE workcom_id=$com_id;"; $result = $sql_object->DBQuery ($q); return $result; } } /** * workshop_com::MoveCom() * déplacement d'une discussion vers un autre groupe * * @access public * @param int $ID identifiant du message * @param int $old_wg_id identifiant de l'ancien groupe de travail * @param int $new_wg_id identifiant du nouveau groupe de travail * @param object $sql_object * @return bool $result */ function MoveCom($id, $old_wg_id, $new_wg_id, $sql_object) { global $l21auth; // Notify the beginning of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.before_move', array('id' => $id, 'old_wg_id' => $old_wg_id, 'new_wg_id' => $new_wg_id))); $id = strip_input($sql_object->DBescape($id)); $old_wg_id = strip_input($sql_object->DBescape($old_wg_id)); $new_wg_id = strip_input($sql_object->DBescape($new_wg_id)); // we update the root message $q = "UPDATE " . $this->TDB_COM . " SET workcom_workshop_id ='" . $new_wg_id . "', workcom_last_modify=NOW() WHERE workcom_id =" . $id . ";"; $result = $sql_object->DBQuery($q); // we then update all children $q = "UPDATE " . $this->TDB_COM . " SET workcom_workshop_id ='" . $new_wg_id . "', workcom_last_modify=NOW() WHERE workcom_parent=" . $id . ";"; $result = $sql_object->DBQuery($q); if($result) logfile(LOG_MAINFILE, array('[action] move thread', 'ID='.$id, 'old_workgroup_id='.$old_wg_id, 'new_workgroup_id='.$new_wg_id, 'by_id='.$l21auth->GetSessionElement('id'), 'by_login='.$l21auth->GetSessionElement('login'))); // Notify the end of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.after_move', array('id' => $id, 'old_wg_id' => $old_wg_id, 'new_wg_id' => $new_wg_id))); return $result; } /** * workshop_com::ModifyCom() * modification d'un message * * @access public * @param int $ID identifiant du message * @param array $table_com contient les composants d'un message * @param object $sql_object * @return bool $result */ function ModifyCom($ID, $table_com, $sql_object) { global $l21auth; // Filter data event + return value $r = $this->dispatcher->filter(new sfEvent($this, 'workshopcom.before_modify', array('data' => $table_com, 'id' => $ID)), $table_com); $table_com = $r->getReturnValue(); // image 64 encoded conversion if enabled before escaping content $table_com[1] = convertBase64Images($table_com[1], 'forum-'); $table_com=$sql_object->DBescape($table_com); if ($table_com[0] != '') { $this->SUBJECT = strip_input(trim($table_com[0])); } if ($table_com[1] != '') { $this->BODY = strip_input(trim($table_com[1])); } $this->USER_ID = $table_com[3]; $q = "UPDATE " . $this->TDB_COM . " SET workcom_subject='" . $this->SUBJECT . "', workcom_body='" . $this->BODY . "', workcom_user_id=" . $this->USER_ID . " , workcom_last_modify=NOW() WHERE workcom_id=" . $ID . ";"; $result = $sql_object->DBQuery($q); if($result) logfile(LOG_MAINFILE, array('[action] modify message', 'ID='.$ID, 'by_id='.$l21auth->GetSessionElement('id'), 'by_login='.$l21auth->GetSessionElement('login'))); // Notify the end of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.after_modify', array('data' => $table_com, 'id' => $ID))); return $result; } /** * workshop_com::ModifyComUser() * modification d'un message utilisateur authentifié * * @access public * @param int $ID identifiant du message * @param array $table_com contient les composants d'un message * @param int $user_id identifiant de l'utilisateur * @param object $sql_object * @return bool $result */ function ModifyComUser($ID, $table_com, $user_id, $sql_object, $hasrights) { global $l21auth; // Filter data event + return value $r = $this->dispatcher->filter(new sfEvent($this, 'workshopcom.before_modify_auth', array('data' => $table_com, 'id' => $ID, 'user_id' => $user_id)), $table_com); $table_com = $r->getReturnValue(); $table_com=$sql_object->DBescape($table_com); if ($table_com[0] != '') { $this->SUBJECT = strip_input(trim($table_com[0])); } if ($table_com[1] != '') { $this->BODY = strip_input(trim($table_com[1]), ''); } $result_user = $this->_getUserId($ID, $sql_object); if ($result_user != $user_id && $hasrights == false) { $result = _t('workshop','not_author'); } else { $q = "UPDATE " . $this->TDB_COM . " SET workcom_subject='" . $this->SUBJECT . "', workcom_body='" . $this->BODY . "' , workcom_last_modify=NOW() WHERE workcom_id=" . $ID . ";"; $result = $sql_object->DBQuery($q); if($result) logfile(LOG_MAINFILE, array('[action] modify message by author', 'ID='.$ID, 'user_id='.$user_id, 'by_id='.$l21auth->GetSessionElement('id'), 'by_login='.$l21auth->GetSessionElement('login'))); } // Notify the end of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.after_modify_auth', array('data' => $table_com, 'id' => $ID, 'user_id' => $user_id, 'has_rights' => $hasrights))); return $result; } /** * workshop_com::_getUserId() * obtention de l'id d'un auteur de message * * @param object $sql_object * @param integer $mes_id * @return integer $result[0]['workcom_user_id'] */ function _getUserId($mes_id, $sql_object) { // Notify the end of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.get_userid', array('id' => $mes_id))); $q = "SELECT workcom_user_id FROM " . $this->TDB_COM . " WHERE workcom_id=" . $mes_id . ";"; $result = $sql_object->DBSelect($q); return $result[0]['workcom_user_id']; } /** * workshop_com::getReadMessages() * obtention des messages lus par l'utilisateur * * @param object $sql_object * @return array */ function getReadMessages($sql_object) { $user_id = $GLOBALS['l21auth']->GetSessionElement('id'); // Notify the call of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.get_readmessage', array('id' => $user_id))); $q = "SELECT user_id, user_forums FROM " . T_USER . " WHERE user_id=" . $user_id . ";"; $r = $sql_object->DBSelect($q); if(isset($r[0]['user_id'])) { if(empty($r[0]['user_forums'])) return array(); else return unserialize($r[0]['user_forums']); } return false; } /** * workshop_com::setReadMessages() * conservation des messages lus par l'utilisateur * * @param object $workshop_id * @param integer $topic_id * @param object $sql_object * @return true */ function setReadMessages($workshop_id, $topic_id, $sql_object) { $user_id = $GLOBALS['l21auth']->GetSessionElement('id'); $read_messages = $this->getReadMessages($sql_object); // Notify the call of the current method $this->dispatcher->notify(new sfEvent($this, 'workshopcom.set_readmessage', array('id' => $user_id, 'topic_id' => $topic_id, 'workshop_id' => $workshop_id))); $q = "SELECT user_id, user_forums FROM " . T_USER . " WHERE user_id=" . $user_id . ";"; $r = $sql_object->DBSelect($q); $data=$GLOBALS['sql_object']->DBSelect(SQL_getLatestMessage($workshop_id, $topic_id)); if(isset($data[0]['workcom_id'])) { // we set last messages id to discussion $read_messages[$topic_id] = $data[0]['workcom_id']; } else $read_messages[$topic_id] = -1; $q = "UPDATE " . T_USER . " SET user_forums = '" . serialize($read_messages) . "' WHERE user_id=" . $user_id . ";"; $r = $sql_object->DBQuery($q); return true; } } ?>