/** * * @param string $dsn - a valid data source name * @return UserDataHandler instance */ public static function instance($dsn = NULL) { if (self::$instance == NULL || self::$tester_dsn != $dsn) { self::$instance = new UserDataHandler($dsn); } return self::$instance; }
*/ require_once ROOT_DIR . '/include/module_init.inc.php'; //$self = whoami(); $self = 'list_chatrooms'; // x template require_once 'include/comunica_functions.inc.php'; require_once 'include/ChatRoom.inc.php'; require_once 'include/ChatDataHandler.inc.php'; $status = translateFN('lista delle chatrooms'); // display message that explains the functionality of the current script $help = translateFN("Da qui l'utente puo' creare una nuova chatroom inserendo i valori negli appositi campi.\n\t <br><br>Attenzione!<br>Per il corretto funzionamento della chat e' importante inserire i valori corretti."); $star = translateFN("I campi contrassegnati con * sono obbligatori, non possono essere lasciati vuoti!"); $status = translateFN("Creazione di una chatroom"); // initialize a new UserDataHandler object //$udh = new UserDataHandler(); $udh = UserDataHandler::instance($_SESSION['sess_selected_tester_dsn']); // initialize a new form object $f = new Tform(); // different chat type options are available for admins and for tutors if ($id_profile == AMA_TYPE_SWITCHER or $id_profile == AMA_TYPE_TUTOR) { $options_of_chat_types = array('Classe' => 'Classe', 'Pubblica' => 'Pubblica'); } /* * if($id_profile == AMA_TYPE_TUTOR){ $options_of_chat_types = array('Privata' => 'Privata', 'Classe' => 'Classe', 'Pubblica'=>'Pubblica'); // $options_of_chat_types = array('Privata' => 'Privata'); } *
/** * get all data for a given message (only called while reading a message) * * @access public * * @param $user_id - id of the user of the spool * @param $msg_id - id of the message * * @return an hash with keys: * id_messaggio, * data_ora, * tipo, * titolo, * mittente*, * destinatari**, * priorita, * testo * * *mittente is a username * **destinatari is a CVS list of usernames * **/ public function get_message($user_id, $msg_id) { // logger("entered MessageHandler::get_message - ". // "[user_id = $user_id, msg_id=$msg_id]", 3); // create generic instance $spool = new Spool($user_id, $this->dsn); // get message content and recipients' ids list $res_ar = $spool->get_message_info($msg_id); //vito, 2 feb 2009: qui potrebbe non aver trovato il messaggio if (AMA_DataHandler::isError($res_ar)) { return new AMA_Error(AMA_ERR_READ_MSG); } list($message_ha, $recipients_ids_ar) = $res_ar; // create instance of UserDataHandler //vito, 26 settembre 2008 //$udh = new UserDataHandler(); $udh = UserDataHandler::instance($this->dsn); // transform sender id into sender username $sender_id = $message_ha['id_mittente']; $res_ar = $udh->find_users_list(array("username"), "id_utente={$sender_id}"); if (AMA_DataHandler::isError($res_ar)) { return new AMA_Error(AMA_ERR_READ_MSG); } $sender_username = $res_ar[0][1]; // transform recipients' ids array into usernames array $recipients_usernames_ar = array(); foreach ($recipients_ids_ar as $rid) { // get username of the current id ($rid) $res_ar = $udh->find_users_list(array("username"), "id_utente={$rid}"); if (AMA_DataHandler::isError($res_ar)) { return new AMA_Error(AMA_ERR_READ_MSG); } if (array_key_exists(0, $res_ar)) { $recipients_usernames_ar[] = $res_ar[0][1]; } } // create CSV list starting from array $recipients_usernames = implode(",", $recipients_usernames_ar); // adapt message hash $message_ha['mittente'] = $sender_username; $message_ha['destinatari'] = $recipients_usernames; // set message as read $res = $spool->_set_message($msg_id, "read", 'R'); if (AMA_DataHandler::isError($res)) { return new AMA_Error(AMA_ERR_UPDATE); } // return values return $message_ha; }