/** * Get list of all announcements in the given or current course. * * @param array $thisCourse * @param int $limit number of records to return * @param int $startTime * @param bool $visibleOnly * @return array of array(id, title, content, time, visibility, rank) * @since 1.7 */ function announcement_get_course_item_list($thisCourse, $limit = null, $startTime = null, $visibleOnly = true) { // **** Caution: has to get fixed ! $tableAnn = get_conf('courseTablePrefix') . $thisCourse['db'] . get_conf('dbGlu') . 'announcement'; // **** $sql = "SELECT '" . claro_sql_escape($thisCourse['sysCode']) . "' AS `courseSysCode`, \n" . "'" . claro_sql_escape($thisCourse['officialCode']) . "' AS `courseOfficialCode`, \n" . "'CLANN' AS `toolLabel`,\n" . "CONCAT(`temps`, ' ', '00:00:00') AS `date`, \n" . "CONCAT(`title`,' - ',`contenu`) AS `content`, \n" . "`visibility`, \n" . "`visibleFrom`, \n" . "`visibleUntil` \n" . "FROM `" . $tableAnn . "` \n" . "WHERE CONCAT(`title`, `contenu`) != '' \n" . ($startTime ? '' : "AND DATE_FORMAT( `temps`, '%Y %m %d') >= '" . date('Y m d', (double) $startTime) . "' \n") . ($visibleOnly ? " AND visibility = 'SHOW' \n" : '') . "ORDER BY `date` DESC \n" . ($limit ? "LIMIT " . (int) $limit : ''); return claro_sql_query_fetch_all_cols($sql); }
/** * Get installed module list, its effect is * to return an array containing the installed module's labels * @param string $type : type of the module that must be returned, * if null, then all the modules are returned * @return array containing the labels of the modules installed * on the platform * false if query failed */ function get_installed_module_list($type = null) { $tbl = claro_sql_get_main_tbl(); $sql = "SELECT label FROM `" . $tbl['module'] . "`"; if (!is_null($type)) { $sql .= " WHERE `type`= '" . claro_sql_escape($type) . "'"; } $moduleList = claro_sql_query_fetch_all_cols($sql); if (is_array($moduleList) && array_key_exists('label', $moduleList)) { return $moduleList['label']; } else { return array(); } }
function init_default_right_profile() { require_once get_conf('includePath') . '/lib/right/profileToolRight.class.php'; $tbl_mdb_names = claro_sql_get_tbl(array('course_tool', 'right_profile', 'right_rel_profile_action', 'right_action')); $sql = " SELECT `id` as `toolId`\n FROM `" . $tbl_mdb_names['course_tool'] . "`"; $result = claro_sql_query_fetch_all_cols($sql); $toolList = $result['toolId']; /** * Initialise anonymous profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(ANONYMOUS_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'user'); $profileAction->save(); /** * Initialise guest profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(GUEST_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'user'); $profileAction->save(); /** * Initialise user profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(USER_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'user'); $profileAction->save(); /** * Initialise manager profile */ $profile = new RightProfile(); $profile->load(claro_get_profile_id(MANAGER_PROFILE)); $profileAction = new RightProfileToolRight(); $profileAction->load($profile); $profileAction->setToolListRight($toolList, 'manager'); $profileAction->save(); return true; }
public function deleteForUser($userId, $date = null) { if (!is_null($date) && !empty($date)) { $dateCondition = " AND `date` < FROM_UNIXTIME('" . (int) $date . "') "; } // get data to delete from exercise tracking table $sql = "SELECT `id`\n FROM `" . $this->tbl_qwz_tracking . "`\n WHERE `user_id` = " . (int) $userId . $dateCondition; $exeList = claro_sql_query_fetch_all_cols($sql); if (is_array($exeList['id']) && !empty($exeList['id'])) { // delete $sql = "DELETE FROM `" . $this->tbl_qwz_tracking . "`\n WHERE `user_id` = " . (int) $userId . $dateCondition; claro_sql_query($sql); // get data to delete $sql = "SELECT `id` FROM `" . $this->tbl_qwz_tracking_questions . "` WHERE `exercise_track_id` IN ('" . implode("', '", $exeList['id']) . "')"; $detailList = claro_sql_query_fetch_all_cols($sql); if (is_array($detailList['id']) && !empty($detailList['id'])) { $sql = "DELETE FROM `" . $this->tbl_qwz_tracking_questions . "` WHERE `exercise_track_id` IN ('" . implode("', '", $exeList['id']) . "')"; claro_sql_query($sql); $sql = "DELETE FROM `" . $this->tbl_qwz_tracking_answers . "` WHERE details_id IN ('" . implode("', '", $detailList['id']) . "')"; claro_sql_query($sql); } } return true; }
} } } $filePathList = array_unique(array_merge($filePathList, $dbSearchResult['path'])); } $fileList = array(); if (count($filePathList) > 0) { /*-------------------------------------------------------------------------- SEARCHING FILES & DIRECTORIES INFOS ON THE DB ------------------------------------------------------------------------*/ /* * Search infos in the DB about the current directory the user is in */ if ($courseContext) { $sql = "SELECT `path`, `visibility`, `comment`\n FROM `" . $dbTable . "`\n WHERE path IN ('" . implode("', '", array_map('claro_sql_escape', $filePathList)) . "')"; $xtraAttributeList = claro_sql_query_fetch_all_cols($sql); } else { $xtraAttributeList = array('path' => array(), 'visibility' => array(), 'comment' => array()); } define('A_DIRECTORY', 1); define('A_FILE', 2); foreach ($filePathList as $thisFile) { $fileAttributeList['path'] = $thisFile; if (is_dir($baseWorkDir . $thisFile)) { $fileAttributeList['type'] = A_DIRECTORY; $fileAttributeList['size'] = false; $fileAttributeList['date'] = false; } elseif (is_file($baseWorkDir . $thisFile)) { $fileAttributeList['type'] = A_FILE; $fileAttributeList['size'] = claro_get_file_size($baseWorkDir . $thisFile); $fileAttributeList['date'] = filemtime($baseWorkDir . $thisFile);
/** * Get the list of invisible documents of the current course * * @param $baseWorkDir path document * @param $cidReq course identifier * @return list of invisible document */ function getInvisibleDocumentList($baseWorkDir, $cidReq = null) { $documentList = array(); if (is_null($cidReq)) { $cid = claro_get_current_course_id(); } else { $cid = $cidReq; } $tbl_cdb_names = claro_sql_get_course_tbl(claro_get_course_db_name_glued($cid)); $tbl_document = $tbl_cdb_names['document']; $sql = "SELECT path\n FROM `" . $tbl_document . "`\n WHERE visibility = 'i'"; $documentList = claro_sql_query_fetch_all_cols($sql); $documentList = $documentList['path']; for ($i = 0; $i < count($documentList); $i++) { $documentList[$i] = '/' . ltrim($baseWorkDir . $documentList[$i], '/'); } return $documentList; }
/** * delete all platform message * */ public function deletePlatformMessage() { $tableName = get_module_main_tbl(array('im_message_status', 'im_recipient', 'im_message')); $sql = "SELECT M.message_id\n" . " FROM `" . $tableName['im_recipient'] . "` AS M\n" . " WHERE M.user_id = 0\n"; $messageId = claro_sql_query_fetch_all_cols($sql); $this->deleteMessageList($messageId['message_id']); }
/** * Send a mail to the user list * * @param int $userIdList list of the user * @param string $message body of the mail * @param string $subject subject of the mail * @param string $specificFrom email of the sender * @param string $specificFromName name to display * @param string $altBody link of the message in case of problem of read * */ protected static function emailNotification($userIdList, $message, $subject, $specificFrom = '', $specificFromName = '', $altBody = '') { if (!is_array($userIdList)) { $userIdList = array($userIdList); } if (count($userIdList) == 0) { return 0; } $tbl = claro_sql_get_main_tbl(); $tbl_user = $tbl['user']; $sql = 'SELECT DISTINCT email FROM `' . $tbl_user . '` WHERE user_id IN (' . implode(', ', array_map('intval', $userIdList)) . ')'; $emailList = claro_sql_query_fetch_all_cols($sql); $emailList = $emailList['email']; $emailList = array_filter($emailList, 'is_well_formed_email_address'); $mail = new ClaroPHPMailer(); $mail->IsHTML(true); if (!empty($altBody)) { $mail->AltBody = $altBody; } if ($specificFrom != '') { $mail->From = $specificFrom; } else { $mail->From = get_conf('administrator_email'); } if ($specificFromName != '') { $mail->FromName = $specificFromName; } else { $mail->FromName = get_conf('administrator_name'); } $mail->Sender = $mail->From; if (strlen($subject) > 78) { $message = get_lang('Subject') . ' : ' . $subject . "<br />\n\n" . $message; $subject = substr($subject, 0, 73) . '...'; } $mail->Subject = $subject; $mail->Body = $message; if (claro_debug_mode()) { $message = '<p>' . get_lang('Subject') . ' : ' . claro_htmlspecialchars($subject) . '</p>' . "\n" . '<p>' . get_lang('Message') . ' : <pre>' . claro_htmlspecialchars($message) . '</pre></p>' . "\n" . '<p>' . get_lang('Sender') . ' : ' . claro_htmlspecialchars($mail->FromName) . ' - ' . claro_htmlspecialchars($mail->From) . '</p>' . "\n" . '<p>' . get_lang('Recipient') . ' : ' . implode(', ', $emailList) . '</p>' . "\n"; pushClaroMessage($message, 'mail'); } $error_list = array(); foreach ($emailList as $thisEmail) { try { $mail->AddAddress($thisEmail); $mail->Send(); } catch (phpmailerException $exception) { if (claro_debug_mode()) { pushClaroMessage('Mail Notification Failed ' . $exception->__toString()); $error_list[] = $thisEmail; } } $mail->ClearAddresses(); } }
/** * return list of groups id where a given user (userId) is tutor * * @param integer $uid uid to find groups where he's tutor * @return array of integer : group list */ function get_tutor_group_list($uid) { $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_student_group = $tbl_cdb_names['group_team']; $sql = "SELECT `id` `group_id`\n FROM `" . $tbl_student_group . "`\n WHERE tutor = " . (int) $uid; $groupList = claro_sql_query_fetch_all_cols($sql); $groupList = $groupList['group_id']; return $groupList; }
$sql = "SELECT '" . claro_sql_escape($thisCourse['sysCode']) . "' AS `courseSysCode`,\n '" . claro_sql_escape($thisCourse['officialCode']) . "' AS `courseOfficialCode`,\n 'CLANN' AS `toolLabel`,\n CONCAT(`temps`, ' ', '00:00:00') AS `date`,\n CONCAT(`title`,' - ',`contenu`) AS `content`\n \n FROM `" . $tableAnn . "`\n WHERE CONCAT(`title`, `contenu`) != ''\n AND DATE_FORMAT( `temps`, '%Y %m %d') >= '" . date('Y m d', claro_get_current_user_data('lastLogin')) . "'\n AND visibility = 'SHOW'\n ORDER BY `date` DESC\n LIMIT 1"; $resultList = claro_sql_query_fetch_all_cols($sql); foreach ($resultList as $colName => $colValue) { if (count($colValue) == 0) { break; } $courseDigestList[$colName] = array_merge($courseDigestList[$colName], $colValue); } } /* * AGENDA : get the next agenda entries of this course from now */ if (is_tool_activated_in_course(get_tool_id_from_module_label('CLCAL'), $thisCourse['sysCode'])) { $tableCal = get_conf('courseTablePrefix') . $thisCourse['db'] . get_conf('dbGlu') . 'calendar_event'; $sql = "SELECT '" . claro_sql_escape($thisCourse['sysCode']) . "' AS `courseSysCode`,\n '" . claro_sql_escape($thisCourse['officialCode']) . "' AS `courseOfficialCode`,\n 'CLCAL' AS `toolLabel`,\n CONCAT(`day`, ' ',`hour`) AS `date`,\n CONCAT(`titre`,' - ',`contenu`) AS `content`\n FROM `" . $tableCal . "`\n \n WHERE CONCAT(`day`, ' ',`hour`) >= CURDATE()\n AND CONCAT(`titre`, `contenu`) != ''\n AND visibility = 'SHOW'\n \n ORDER BY `date`\n LIMIT 1"; $resultList = claro_sql_query_fetch_all_cols($sql); foreach ($resultList as $colName => $colValue) { if (count($colValue) == 0) { break; } $courseDigestList[$colName] = array_merge($courseDigestList[$colName], $colValue); } } } // end foreach($personnalCourseList as $thisCourse) /* * Sort all these digest by date */ array_multisort($courseDigestList['toolLabel'], $courseDigestList['date'], $courseDigestList['courseOfficialCode'], $courseDigestList['courseSysCode'], $courseDigestList['content']); /****************************************************************************** DISPLAY
protected function mergeCourseUsers($uidToRemove, $uidToKeep, $courseId) { $courseTbl = claro_sql_get_course_tbl(claro_get_course_db_name_glued($courseId)); // Get groups for the user to remove $sql = "SELECT team\n FROM `{$courseTbl['group_rel_team_user']}`\n WHERE user= "******"\n SELECT user, team, role, status\n FROM `{$courseTbl['group_rel_team_user']}`\n WHERE user = "******"\n AND team = " . (int) $thisTeam); $toRemove_team_entry = claro_sql_query_fetch_single_row("\n SELECT user, team, role, status\n FROM `{$courseTbl['group_rel_team_user']}`\n WHERE user = "******"\n AND team = " . (int) $thisTeam); if ($toKeep_team_entry) { $status = $toKeep_team_entry['status'] > $toRemove_team_entry['status'] ? null : $toRemove_team_entry['status']; $role = empty($toKeep_team_entry['role']) ? $toRemove_team_entry['role'] : null; if (!is_null($role) || !is_null($status)) { if (!claro_sql_query("UPDATE `{$courseTbl['group_rel_team_user']}`\n SET role = '" . $role . "',\n status = " . $status . "\n WHERE user = "******"\n AND team = " . (int) $thisTeam)) { Console::error("Cannot update user group status for +{$uidToKeep} in group_rel_team_user in {$courseId}:{$thisTeam}"); $this->hasError = true; } } if (!claro_sql_query("DELETE FROM `{$courseTbl['group_rel_team_user']}`\n WHERE user = "******"\n AND team = " . (int) $thisTeam)) { Console::error("Cannot delete user -{$uidToRemove} in group_rel_team_user in {$courseId}:{$thisTeam}"); $this->hasError = true; } } else { if (!claro_sql_query("UPDATE `{$courseTbl['group_rel_team_user']}`\n SET user = "******"\n WHERE user = "******"\n AND team = " . (int) $thisTeam)) { Console::error("Cannot replace -{$uidToRemove} with +{$uidToKeep} in group_rel_team_user {$courseId}:{$thisTeam}"); $this->hasError = true; } } } // Update tracking $sql = "UPDATE `{$courseTbl['tracking_event']}`\n SET user_id = " . (int) $uidToKeep . "\n WHERE user_id = " . (int) $uidToRemove; if (!claro_sql_query($sql)) { Console::error("Cannot replace -{$uidToRemove} with +{$uidToKeep} in tracking_event in course {$courseId}"); $this->hasError = true; } $qwz_tbl_names = get_module_course_tbl(array('qwz_tracking'), $courseId); $sql = "UPDATE `{$qwz_tbl_names['qwz_tracking']}`\n SET user_id = " . (int) $uidToKeep . "\n WHERE user_id = " . (int) $uidToRemove; if (!claro_sql_query($sql)) { Console::error("Cannot replace -{$uidToRemove} with +{$uidToKeep} in qwz_tracking in {$courseId}"); $this->hasError = true; } // Update user info in course $sql = "DELETE FROM `{$courseTbl['userinfo_content']}`\n WHERE user_id = " . (int) $uidToRemove; if (!claro_sql_query($sql)) { Console::error("Cannot remove user info for user -{$uidToRemove} in {$courseId}"); $this->hasError = true; } }
/** * Delete the given category * * @param integer $cat_id * @return boolean wheter success */ function delete_category($cat_id) { if ($cat_id == GROUP_FORUMS_CATEGORY) { return claro_failure::set_failure('GROUP_FORUMS_CATEGORY_REMOVALE_FORBIDDEN'); } $tbl_cdb_names = claro_sql_get_course_tbl(); $tbl_forum_categories = $tbl_cdb_names['bb_categories']; $tbl_forum_forums = $tbl_cdb_names['bb_forums']; $tbl_forum_topics = $tbl_cdb_names['bb_topics']; $sql = 'SELECT `forum_id`, `group_id` FROM `' . $tbl_forum_forums . '` WHERE `cat_id` = "' . $cat_id . '"'; $result = claro_sql_query_fetch_all_cols($sql); $forumIdList = $result['forum_id']; $groupIdList = $result['group_id']; if (count(array_filter($groupIdList, 'is_null')) < count($groupIdList)) { return claro_failure::set_failure('GROUP_FORUM_REMOVALE_FORBIDDEN'); } else { foreach ($forumIdList as $thisForumId) { $sql = 'DELETE FROM `' . $tbl_forum_topics . '` WHERE `forum_id` = "' . (int) $thisForumId . '"'; claro_sql_query($sql); } $sql = 'DELETE FROM `' . $tbl_forum_forums . '` WHERE `cat_id` = "' . (int) $cat_id . '"'; claro_sql_query($sql); $sql = 'DELETE FROM `' . $tbl_forum_categories . '` WHERE `cat_id` = "' . (int) $cat_id . '"'; claro_sql_query($sql); return true; } }
/** * Return all manager id of a course. * * @param String course id * @return Array array of int */ function claro_get_course_manager_id($cid = NULL) { if (is_null($cid)) { if (!claro_is_in_a_course()) { return false; } $cid = claro_get_current_course_id(); } $tableName = get_module_main_tbl(array('rel_course_user')); $sql = "SELECT user_id " . "FROM `" . $tableName['rel_course_user'] . "` " . "WHERE code_cours='" . claro_sql_escape($cid) . "' " . "AND isCourseManager = 1"; $result = claro_sql_query_fetch_all_cols($sql); return $result['user_id']; }
/** * Upgrade right (from main database) to 1.8 * @return step value, 0 if succeed */ function upgrade_main_database_right_to_18() { include_once $GLOBALS['includePath'] . '/lib/right/right_profile.lib.php'; include_once $GLOBALS['includePath'] . '/../install/init_profile_right.lib.php'; $tbl_mdb_names = claro_sql_get_main_tbl(); $tool = 'RIGHT_18'; switch ($step = get_upgrade_status($tool)) { case 1: // add right tables $sqlForUpdate[] = " CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_profile'] . "` (\n `profile_id` int(11) NOT NULL auto_increment,\n `type` enum('COURSE','PLATFORM') NOT NULL default 'COURSE',\n `name` varchar(255) NOT NULL default '',\n `label` varchar(50) NOT NULL default '',\n `description` varchar(255) default '',\n `courseManager` tinyint(4) default '0',\n `mailingList` tinyint(4) default '0',\n `userlistPublic` tinyint(4) default '0',\n `groupTutor` tinyint(4) default '0',\n `locked` tinyint(4) default '0',\n `required` tinyint(4) default '0',\n PRIMARY KEY (`profile_id`),\n KEY `type` (`type`)\n )ENGINE=MyISAM "; $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_action'] . "` (\n `id` int(11) NOT NULL auto_increment,\n `name` varchar(255) NOT NULL default '',\n `description` varchar(255) default '',\n `tool_id` int(11) default NULL,\n `rank` int(11) default '0',\n `type` enum('COURSE','PLATFORM') NOT NULL default 'COURSE',\n PRIMARY KEY (`id`),\n KEY `tool_id` (`tool_id`),\n KEY `type` (`type`)\n )ENGINE=MyISAM "; $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['right_rel_profile_action'] . "` (\n `profile_id` int(11) NOT NULL,\n `action_id` int(11) NOT NULL,\n `courseId` varchar(40) NOT NULL default '',\n `value` tinyint(4) default '0',\n PRIMARY KEY (`profile_id`,`action_id`,`courseId`)\n ) ENGINE=MyISAM "; if (upgrade_apply_sql($sqlForUpdate)) { $step = set_upgrade_status($tool, $step + 1); } else { return $step; } unset($sqlForUpdate); case 2: create_required_profile(); $step = set_upgrade_status($tool, $step + 1); case 3: // Init action/right $sql = " SELECT id\n FROM `" . $tbl_mdb_names['tool'] . "`"; $result = claro_sql_query_fetch_all_cols($sql); $toolIdList = $result['id']; foreach ($toolIdList as $toolId) { // Manage right - Add read action $action = new RightToolAction(); $action->setName('read'); $action->setToolId($toolId); $action->save(); // Manage right - Add edit action $action = new RightToolAction(); $action->setName('edit'); $action->setToolId($toolId); $action->save(); } $step = set_upgrade_status($tool, $step + 1); case 4: init_default_right_profile(); $step = set_upgrade_status($tool, $step + 1); case 5: // set profile_id in rel course_user $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['rel_course_user'] . "` SET `profile_id` = " . claro_get_profile_id(USER_PROFILE) . "\n WHERE `isCourseManager` = 0"; $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['rel_course_user'] . "` SET `profile_id` = " . claro_get_profile_id(MANAGER_PROFILE) . "\n WHERE `isCourseManager` = 1"; // set default profile_id in course if (upgrade_apply_sql($sqlForUpdate)) { $step = set_upgrade_status($tool, $step + 1); } else { return $step; } unset($sqlForUpdate); default: $step = set_upgrade_status($tool, 0); return $step; } return false; }
/** * Send e-mail to Claroline users form their ID a user of Claroline * * Send e-mail to Claroline users form their ID a user of Claroline * default from clause in email address will be the platorm admin adress * default from name clause in email will be the platform admin name and surname * * @author Hugues Peeters <*****@*****.**> * @param int or array $userIdList - sender id's * @param string $message - mail content * @param string $subject - mail subject * @param string $specificFrom (optional) sender's email address * @param string $specificFromName (optional) sender's name * @return int total count of sent email */ function claro_mail_user($userIdList, $message, $subject, $specificFrom = '', $specificFromName = '') { if (!is_array($userIdList)) { $userIdList = array($userIdList); } if (count($userIdList) == 0) { return 0; } $tbl = claro_sql_get_main_tbl(); $tbl_user = $tbl['user']; $sql = 'SELECT DISTINCT email FROM `' . $tbl_user . '` WHERE user_id IN (' . implode(', ', array_map('intval', $userIdList)) . ')'; $emailList = claro_sql_query_fetch_all_cols($sql); $emailList = $emailList['email']; $emailList = array_filter($emailList, 'is_well_formed_email_address'); $mail = new ClaroPHPMailer(); if ($specificFrom != '') { $mail->From = $specificFrom; } else { $mail->From = get_conf('administrator_email'); } if ($specificFromName != '') { $mail->FromName = $specificFromName; } else { $mail->FromName = get_conf('administrator_name'); } $mail->Sender = $mail->From; if (strlen($subject) > 78) { $message = $subject . "\n" . $message; $subject = substr($subject, 0, 73) . '...'; } $mail->Subject = $subject; $mail->Body = $message; $emailSentCount = 0; if (claro_debug_mode()) { $message = '<p>Subject : ' . claro_htmlspecialchars($subject) . '</p>' . "\n" . '<p>Message : <pre>' . claro_htmlspecialchars($message) . '</pre></p>' . "\n" . '<p>From : ' . claro_htmlspecialchars($mail->FromName) . ' - ' . claro_htmlspecialchars($mail->From) . '</p>' . "\n" . '<p>Dest : ' . implode(', ', $emailList) . '</p>' . "\n"; pushClaroMessage($message, 'mail'); } foreach ($emailList as $thisEmail) { $mail->AddAddress($thisEmail); if ($mail->Send()) { $emailSentCount++; } else { if (claro_debug_mode()) { pushClaroMessage($mail->getError(), 'error'); } } $mail->ClearAddresses(); } return $emailSentCount; }
/** * Returns the documents contained into args['curDirPath'] * @param array $args array of parameters, can contain : * - (boolean) recursive : if true, return the content of the requested directory and its subdirectories, if any. Default = true * - (String) curDirPath : returns the content of the directory specified by this path. Default = '' (root) * @throws InvalidArgumentException if $cid is missing * @webservice{/module/MOBILE/CLDOC/getResourceList/cidReq/[?recursive=BOOL&curDirPath='']} * @ws_arg{Method,getResourcesList} * @ws_arg{cidReq,SYSCODE of requested cours} * @ws_arg{recursive,[Optionnal: if true\, return the content of the requested directory and its subdirectories\, if any. Default = true]} * @ws_arg{curDirPath,[Optionnal: returns the content of the directory specified by this path. Default = '' (root)]} * @return array of document object */ function getResourcesList($args) { $recursive = isset($args['recursive']) ? $args['recursive'] : true; $curDirPath = isset($args['curDirPath']) ? $args['curDirPath'] : ''; $cid = claro_get_current_course_id(); if (is_null($cid)) { throw new InvalidArgumentException('Missing cid argument!'); } elseif (!claro_is_course_allowed()) { throw new RuntimeException('Not allowed', 403); } /* READ CURRENT DIRECTORY CONTENT = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ $claroline = Claroline::getInstance(); $exSearch = false; $groupContext = FALSE; $courseContext = TRUE; $dbTable = get_module_course_tbl(array('document'), $cid); $dbTable = $dbTable['document']; $docToolId = get_course_tool_id('CLDOC'); $groupId = claro_get_current_group_id(); $date = $claroline->notification->getLastActionBeforeLoginDate(claro_get_current_user_id()); if (!defined('A_DIRECTORY')) { define('A_DIRECTORY', 1); } if (!defined('A_FILE')) { define('A_FILE', 2); } $baseWorkDir = get_path('coursesRepositorySys') . claro_get_course_path($cid) . '/document'; /*---------------------------------------------------------------------------- LOAD FILES AND DIRECTORIES INTO ARRAYS ----------------------------------------------------------------------------*/ $searchPattern = ''; $searchRecursive = false; $searchBasePath = $baseWorkDir . $curDirPath; $searchExcludeList = array(); $searchBasePath = secure_file_path($searchBasePath); if (false === ($filePathList = claro_search_file(search_string_to_pcre($searchPattern), $searchBasePath, $searchRecursive, 'ALL', $searchExcludeList))) { switch (claro_failure::get_last_failure()) { case 'BASE_DIR_DONT_EXIST': pushClaroMessage($searchBasePath . ' : call to an unexisting directory in groups'); break; default: pushClaroMessage('Search failed'); break; } $filePathList = array(); } for ($i = 0; $i < count($filePathList); $i++) { $filePathList[$i] = str_replace($baseWorkDir, '', $filePathList[$i]); } if ($exSearch && $courseContext) { $sql = "SELECT path FROM `" . $dbTable . "`\n\t\t\t\t\tWHERE comment LIKE '%" . claro_sql_escape($searchPattern) . "%'"; $dbSearchResult = claro_sql_query_fetch_all_cols($sql); $filePathList = array_unique(array_merge($filePathList, $dbSearchResult['path'])); } $fileList = array(); if (count($filePathList) > 0) { /*-------------------------------------------------------------------------- SEARCHING FILES & DIRECTORIES INFOS ON THE DB ------------------------------------------------------------------------*/ /* * Search infos in the DB about the current directory the user is in */ if ($courseContext) { $sql = "SELECT `path`, `visibility`, `comment`\n\t\t\t\t\t\tFROM `" . $dbTable . "`\n\t\t\t\t\t\t\t\tWHERE path IN ('" . implode("', '", array_map('claro_sql_escape', $filePathList)) . "')"; $xtraAttributeList = claro_sql_query_fetch_all_cols($sql); } else { $xtraAttributeList = array('path' => array(), 'visibility' => array(), 'comment' => array()); } foreach ($filePathList as $thisFile) { $fileAttributeList['cours']['sysCode'] = $cid; $fileAttributeList['path'] = $thisFile; $fileAttributeList['resourceId'] = $thisFile; $tmp = explode('/', $thisFile); if (is_dir($baseWorkDir . $thisFile)) { $fileYear = date('n', time()) < 8 ? date('Y', time()) - 1 : date('Y', time()); $fileAttributeList['title'] = $tmp[count($tmp) - 1]; $fileAttributeList['isFolder'] = true; $fileAttributeList['type'] = A_DIRECTORY; $fileAttributeList['size'] = 0; $fileAttributeList['date'] = $fileYear . '-09-20'; $fileAttributeList['extension'] = ""; $fileAttributeList['url'] = null; } elseif (is_file($baseWorkDir . $thisFile)) { $fileAttributeList['title'] = implode('.', explode('.', $tmp[count($tmp) - 1], -1)); $fileAttributeList['type'] = A_FILE; $fileAttributeList['isFolder'] = false; $fileAttributeList['size'] = claro_get_file_size($baseWorkDir . $thisFile); $fileAttributeList['date'] = date('Y-m-d', filemtime($baseWorkDir . $thisFile)); $fileAttributeList['extension'] = get_file_extension($baseWorkDir . $thisFile); $fileAttributeList['url'] = $_SERVER['SERVER_NAME'] . claro_get_file_download_url($thisFile); } $xtraAttributeKey = array_search($thisFile, $xtraAttributeList['path']); if ($xtraAttributeKey !== false) { $fileAttributeList['description'] = $xtraAttributeList['comment'][$xtraAttributeKey]; $fileAttributeList['visibility'] = $xtraAttributeList['visibility'][$xtraAttributeKey] == 'v'; unset($xtraAttributeList['path'][$xtraAttributeKey]); } else { $fileAttributeList['description'] = null; $fileAttributeList['visibility'] = true; } $notified = $claroline->notification->isANotifiedDocument($cid, $date, claro_get_current_user_id(), $groupId, $docToolId, $fileAttributeList, false); $fileAttributeList['notifiedDate'] = $notified ? $date : $fileAttributeList['date']; $d = new DateTime($date); $d->sub(new DateInterval('P1D')); $fileAttributeList['seenDate'] = $d->format('Y-m-d'); if ($fileAttributeList['visibility'] || claro_is_allowed_to_edit()) { $fileList[] = $fileAttributeList; } } // end foreach $filePathList } if ($recursive) { foreach ($fileList as $thisFile) { if ($thisFile['type'] == A_DIRECTORY) { $args = array('curDirPath' => $thisFile['path'], 'recursive' => true); $new_list = $this->getResourcesList($args); $fileList = array_merge($fileList, $new_list); } } } return $fileList; }
/** * @return list of users wich have status to receive system notification * @author Christophe Gesche <*****@*****.**> * */ function claro_get_uid_of_system_notification_recipient() { $tbl = claro_sql_get_main_tbl(); $sql = "SELECT user_id AS id\n FROM `" . $tbl['user'] . "` AS u\n INNER JOIN `" . $tbl['user_property'] . "` AS up\n ON up.userId = u.user_id\n WHERE up.propertyId = 'adminContactForSystemNotification'\n AND up.propertyValue = 1\n AND up.scope = 'contacts'\n "; $resultList = claro_sql_query_fetch_all_cols($sql); return $resultList['id']; }