public function __construct($courseId)
 {
     $this->courseId = $courseId;
     $courseCode = ClaroCourse::getCodeFromId($this->courseId);
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_rel_course_portlet = $tbl_mdb_names['rel_course_portlet'];
     $sql = "SELECT id, courseId, rank, label, visible\n                FROM `{$tbl_rel_course_portlet}`\n                WHERE `courseId` = {$this->courseId}\n                ORDER BY `rank` ASC";
     $result = Claroline::getDatabase()->query($sql);
     foreach ($result as $portletInfos) {
         // Require the proper portlet class
         $portletPath = get_module_path($portletInfos['label']) . '/connector/coursehomepage.cnr.php';
         $portletName = $portletInfos['label'] . '_Portlet';
         if (file_exists($portletPath)) {
             require_once $portletPath;
         } else {
             echo "Le fichier {$portletPath} est introuvable<br/>";
         }
         if (class_exists($portletName)) {
             $portlet = new $portletName($portletInfos['id'], $courseCode, $portletInfos['courseId'], $portletInfos['rank'], $portletInfos['label'], $portletInfos['visible']);
             $this->portlets[] = $portlet;
         } else {
             echo "Can't find the class {$portletName}_portlet<br/>";
             return false;
         }
     }
 }
function upgrade_main_database_to_17()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tool = 'MAINDB17';
    switch ($step = get_upgrade_status($tool)) {
        case 1:
            // create notification table
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['notify'] . "` (\n              `id` int(11) NOT NULL auto_increment,\n              `course_code` varchar(40) NOT NULL default '0',\n              `tool_id` int(11) NOT NULL default '0',\n              `ressource_id` varchar(255) NOT NULL default '0',\n              `group_id` int(11) NOT NULL default '0',\n              `user_id` int(11) NOT NULL default '0',\n              `date` datetime default '0000-00-00 00:00:00',\n              PRIMARY KEY  (`id`),\n              KEY `course_id` (`course_code`)\n            ) ENGINE=MyISAM";
            // add enrollment key
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['course'] . "` ADD `enrollment_key` varchar(255) default NULL";
            // remove old columns : cahier_charges, scoreShow, description
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['course'] . "` DROP COLUMN `cahier_charges`";
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['course'] . "` DROP COLUMN `scoreShow`";
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['course'] . "` DROP COLUMN `description`";
            // add index in rel_class_user table
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['rel_class_user'] . "` ADD INDEX ( `user_id` ) ";
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['rel_class_user'] . "` ADD INDEX ( `class_id` ) ";
            if (upgrade_apply_sql($sqlForUpdate)) {
                $step = set_upgrade_status($tool, 2);
            } else {
                return $step;
            }
        case 2:
            register_tool_in_main_database('CLWIKI__', 'wiki/wiki.php', 'wiki.gif');
            $step = set_upgrade_status($tool, 0);
            return $step;
        default:
            $step = set_upgrade_status($tool, 0);
            return $step;
    }
    return false;
}
 /**
  * Constructor
  */
 public function __construct()
 {
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $this->tbl['profile'] = $tbl_mdb_names['right_profile'];
     $this->tbl['rel_profile_action'] = $tbl_mdb_names['right_rel_profile_action'];
     $this->tbl['action'] = $tbl_mdb_names['right_action'];
     $this->tbl['course_tool'] = $tbl_mdb_names['tool'];
 }
 public function __construct($courseId)
 {
     $this->courseId = $courseId;
     $courseCode = ClaroCourse::getCodeFromId($this->courseId);
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_rel_course_portlet = $tbl_mdb_names['rel_course_portlet'];
     $sql = "SELECT id, courseId, rank, label, visible\n                FROM `{$tbl_rel_course_portlet}`\n                WHERE `courseId` = {$this->courseId}\n                ORDER BY `rank` ASC";
     $this->portlets = Claroline::getDatabase()->query($sql);
 }
Exemple #5
0
 public function __construct($courseId, $groupId = null)
 {
     $this->courseId = $courseId;
     $this->groupId = $groupId;
     $tblNameList = array('chat');
     $tbl_chat_names = get_module_course_tbl($tblNameList, $this->courseId);
     $this->tblChatMsg = $tbl_chat_names['chat'];
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $this->tblUser = $tbl_mdb_names['user'];
 }
Exemple #6
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->id = '';
     $this->name = '';
     $this->description = '';
     $this->toolId = '';
     $this->type = PROFILE_TYPE_COURSE;
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $this->tbl['action'] = $tbl_mdb_names['right_action'];
     $this->tbl['rel_profile_action'] = $tbl_mdb_names['right_rel_profile_action'];
 }
Exemple #7
0
 function buildRecords($exportUserInfo = true)
 {
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_user = $tbl_mdb_names['user'];
     $tbl_rel_course_user = $tbl_mdb_names['rel_course_user'];
     $tbl_cdb_names = claro_sql_get_course_tbl(claro_get_course_db_name_glued($this->course_id));
     $tbl_team = $tbl_cdb_names['group_team'];
     $tbl_rel_team_user = $tbl_cdb_names['group_rel_team_user'];
     $username = claro_is_platform_admin() && get_conf('export_sensitive_data_for_admin', false) || get_conf('export_user_username', false) ? "`U`.`username`     AS `username`," : "";
     if (claro_is_platform_admin() && get_conf('export_sensitive_data_for_admin', false) || get_conf('export_user_password', false)) {
         if (claro_is_platform_admin() && get_conf('export_sensitive_data_for_admin', false) || get_conf('export_user_password_encrypted', true)) {
             $password = "******";
         } else {
             $password = "******";
         }
     } else {
         $password = '';
     }
     // get user list
     $sql = "SELECT `U`.`user_id`      AS `userId`,\n                       `U`.`nom`          AS `lastname`,\n                       `U`.`prenom`       AS `firstname`,\n                       {$username}\n                       {$password}\n                       `U`.`email`        AS `email`,\n                       `U`.`officialCode`     AS `officialCode`,\n                       GROUP_CONCAT(`G`.`id`) AS `groupId`,\n                       GROUP_CONCAT(`G`.`name`) AS `groupName`\n               FROM\n                    (\n                    `" . $tbl_user . "`           AS `U`,\n                    `" . $tbl_rel_course_user . "` AS `CU`\n                    )\n               LEFT JOIN `" . $tbl_rel_team_user . "` AS `GU`\n                ON `U`.`user_id` = `GU`.`user`\n               LEFT JOIN `" . $tbl_team . "` AS `G`\n                ON `GU`.`team` = `G`.`id`\n               WHERE `U`.`user_id` = `CU`.`user_id`\n               AND   `CU`.`code_cours`= '" . claro_sql_escape($this->course_id) . "'\n               GROUP BY U.`user_id`\n               ORDER BY U.`user_id`";
     $userList = claro_sql_query_fetch_all($sql);
     // build recordlist with good values for answers
     if (is_array($userList) && !empty($userList)) {
         // add titles at row 0, for that get the keys of the first row of array
         $this->recordList[0] = array_keys($userList[0]);
         $i = 1;
         $userIdList = array();
         foreach ($userList as $user) {
             $userIdList[$user['userId']] = $i;
             if (!(claro_is_platform_admin() && get_conf('export_sensitive_data_for_admin', false) || get_conf('export_user_id', false))) {
                 $user['userId'] = $i;
             }
             // $this->recordList is defined in parent class csv
             $this->recordList[$i] = $user;
             $i++;
         }
         if ($exportUserInfo) {
             $userInfoList = new UserInfoList($this->course_id);
             $userInfoLabelList = $userInfoList->getUserInfoLabels();
             foreach ($userInfoLabelList as $catId => $catTitle) {
                 $this->recordList[0][] = $catTitle;
                 $userCatInfo = $userInfoList->getUserInfo($catId);
                 foreach ($userCatInfo as $userCatInfo) {
                     $this->recordList[$userIdList[$userCatInfo['userId']]][] = $userCatInfo['content'];
                 }
             }
         }
     }
     if (is_array($this->recordList) && !empty($this->recordList)) {
         return true;
     } else {
         return false;
     }
 }
function upgrade_main_database_to_16()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tool = 'MAINDB16';
    switch ($step = get_upgrade_status($tool)) {
        case 1:
            $lenForDbNameOfACourse = 20 + 30;
            // (max for prefix + max  for code course);
            // Update table admin
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['admin'] . "` CHANGE `idUser` `idUser` int(11) unsigned NOT NULL default '0'";
            // Create new table class
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['class'] . "` (\n              `id` int(11) NOT NULL auto_increment,\n              `name` varchar(100) NOT NULL default '',\n              `class_parent_id` int(11) default NULL,\n              `class_level` int(11) NOT NULL default '0',\n              PRIMARY KEY  (`id`)\n            ) ENGINE=MyISAM";
            // Create new table rel_class_user
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['rel_class_user'] . "` (\n              `id` int(11) NOT NULL auto_increment,\n              `user_id` int(11) NOT NULL default '0',\n              `class_id` int(11) NOT NULL default '0',\n              PRIMARY KEY  (`id`)\n            ) ENGINE=MyISAM";
            // Update table user_id
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['user'] . "` CHANGE `user_id` `user_id` int(11) unsigned NOT NULL auto_increment";
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['user'] . "` CHANGE `creatorId` `creatorId` int(11) unsigned default NULL";
            // Update table cours
            $sqlForUpdate[] = " ALTER IGNORE TABLE `" . $tbl_mdb_names['course'] . "` CHANGE `dbName` `dbName` varchar(" . $lenForDbNameOfACourse . ") default NULL";
            // Create new table config_file
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS `" . $tbl_mdb_names['config_file'] . "` (\n              `config_code` varchar(30) NOT NULL default '',\n              `config_hash` varchar(40) NOT NULL default '',\n              PRIMARY KEY  (`config_code` )\n            ) ENGINE=MyISAM  AVG_ROW_LENGTH=48";
            // Create new table sso
            $sqlForUpdate[] = "CREATE TABLE IF NOT EXISTS`" . $tbl_mdb_names['sso'] . "` (\n              `id` int(11) NOT NULL auto_increment,\n              `cookie` varchar(255) NOT NULL default '',\n              `rec_time` datetime NOT NULL default '0000-00-00 00:00:00',\n              `user_id` int(11) NOT NULL default '0',\n              PRIMARY KEY  (`id`)\n            ) ENGINE=MyISAM";
            // Update course tool icon
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "` SET `icon` = 'announcement.gif' WHERE `claro_label` = 'CLANN___'";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "` SET `icon` = 'assignment.gif' WHERE `claro_label` = 'CLWRK___'";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "` SET `icon` = 'chat.gif' WHERE `claro_label` = 'CLCHT___'";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "` SET `icon` = 'document.gif' WHERE `claro_label` = 'CLDOC___'";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "` SET `icon` = 'learnpath.gif' WHERE `claro_label` = 'CLLNP___'";
            $sqlForUpdate[] = "UPDATE `" . $tbl_mdb_names['tool'] . "` SET `icon` = 'user.gif' WHERE `claro_label` = 'CLUSR___'";
            // Update table track_e_default
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['track_e_default'] . "` CHANGE `default_user_id` `default_user_id` int(11) NOT NULL default '0'";
            // Update table login_user_id
            $sqlForUpdate[] = "ALTER IGNORE TABLE `" . $tbl_mdb_names['track_e_login'] . "` CHANGE `login_user_id` `login_user_id` int(11) NOT NULL default '0'";
            if (upgrade_apply_sql($sqlForUpdate)) {
                $step = set_upgrade_status($tool, 2);
            } else {
                return $step;
            }
        case 2:
            if (fill_table_config_with_md5()) {
                $step = set_upgrade_status($tool, 0);
            } else {
                return $step;
            }
        default:
            $step = set_upgrade_status($tool, 0);
            return $step;
    }
    return false;
}
Exemple #9
0
/**
 * Get all the settings from a specific tool
 *
 * @author Hugues Peeters <*****@*****.**>
 * @param int $toolId id of the tool
 * @return array containing 'id', 'name', 'visibility', 'rank', 'url', 'label',
 *                          'icon', 'access_manager'
 */
function get_course_tool_settings($toolId)
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_tool_list = $tbl_mdb_names['tool'];
    $tbl_cdb_names = claro_sql_get_course_tbl();
    $tbl_course_tool_list = $tbl_cdb_names['tool'];
    $sql = "SELECT tl.id                               id,\n                   tl.script_name                      name,\n                   tl.visibility                       visibility,\n                   tl.rank                             rank,\n                   IFNULL(ct.script_url,tl.script_url) url,\n                   ct.claro_label                      label,\n                   ct.icon                             icon,\n                   ct.access_manager                   access_manager\n\n            FROM      `" . $tbl_course_tool_list . "`             tl\n\n            LEFT JOIN `" . $tbl_tool_list . "` ct\n\n            ON        ct.id = tl.tool_id\n\n            WHERE tl.id = " . (int) $toolId;
    $toolList = claro_sql_query_fetch_all($sql);
    if (count($toolList) > 0) {
        // this function is supposed to return only one tool
        // That's why we extract it immediately from the result array
        list($toolSetting) = claro_sql_query_fetch_all($sql);
    }
    return $toolSetting;
}
Exemple #10
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $this->id = 0;
     $this->name = '';
     $this->label = '';
     $this->type = PROFILE_TYPE_COURSE;
     $this->description = '';
     $this->isLocked = false;
     $this->isRequired = false;
     $this->isCourseManager = false;
     $this->isTutor = false;
     $this->isUserPublic = true;
     $this->isEmailNotify = true;
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $this->tbl['profile'] = $tbl_mdb_names['right_profile'];
 }
Exemple #11
0
 public static function setForUser($_uid)
 {
     $tbl = claro_sql_get_main_tbl();
     $ssoCookieExpireTime = time() + get_conf('ssoCookiePeriodValidity', 3600);
     $ssoCookieValue = md5(time() . rand(100, 1000000));
     $sql = "UPDATE `{$tbl['sso']}`\n" . "SET cookie    = '" . $ssoCookieValue . "',\n" . "rec_time  = NOW()\n" . "WHERE user_id = " . (int) $_uid;
     $affectedRowCount = claro_sql_query_affected_rows($sql);
     if ($affectedRowCount < 1) {
         $sql = "INSERT INTO `{$tbl['sso']}`\n" . "SET cookie = '" . $ssoCookieValue . "',\n" . "rec_time = NOW(),\n" . "user_id = " . (int) $_uid;
         claro_sql_query($sql);
     }
     return setcookie(get_conf('ssoCookieName', 'clarolineSsoCookie'), $ssoCookieValue, $ssoCookieExpireTime, get_conf('ssoCookiePath', '/'), get_conf('ssoCookieDomain', 'sso.claroline.net'));
     // Note. $ssoCookieName, $ssoCookieValussoCookieExpireTime,
     //       $soCookiePath and $ssoCookieDomain are coming from
     //       claroline/inc/conf/auth.conf.php
 }
 public function render()
 {
     // Select current course's datas
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_courses = $tbl_mdb_names['course'];
     $curdate = claro_mktime();
     $sql = "SELECT course.cours_id,\n                       course.code                  AS `sysCode`,\n                       course.directory             AS `directory`,\n                       course.administrativeNumber  AS `officialCode`,\n                       course.dbName                AS `db`,\n                       course.intitule              AS `title`,\n                       course.titulaires            AS `titular`,\n                       course.language              AS `language`,\n                       course.access                AS `access`,\n                       course.status,\n                       course.sourceCourseId,\n                       UNIX_TIMESTAMP(course.expirationDate) AS expirationDate,\n                       UNIX_TIMESTAMP(course.creationDate)   AS creationDate\n                FROM `" . $tbl_courses . "` AS course\n                WHERE course.code = " . Claroline::getDatabase()->quote($this->courseCode);
     $result = Claroline::getDatabase()->query($sql);
     $courseData = $result->fetch(Database_ResultSet::FETCH_ASSOC);
     $courseEventList = get_agenda_next_items_list($courseData, 10, $this->month, $this->year);
     if (is_array($courseEventList)) {
         $courseDigestList = array();
         foreach ($courseEventList as $thisEvent) {
             $eventLine = trim(strip_tags($thisEvent['title']));
             if ($eventLine == '') {
                 $eventContent = trim(strip_tags($thisEvent['content']));
                 $eventLine = substr($eventContent, 0, 60) . (strlen($eventContent) > 60 ? ' (...)' : '');
             }
             $eventDate = $thisEvent['day'];
             if (!array_key_exists($eventDate, $courseDigestList)) {
                 $courseDigestList[$eventDate] = array();
                 $courseDigestList[$eventDate]['eventList'] = array();
                 $courseDigestList[$eventDate]['date'] = $eventDate;
             }
             $courseDigestList[$eventDate]['eventList'][] = array('id' => $thisEvent['id'], 'hour' => $thisEvent['hour'], 'location' => $thisEvent['location'], 'courseOfficialCode' => $courseData['officialCode'], 'courseSysCode' => $courseData['sysCode'], 'content' => $eventLine, 'url' => get_path('url') . '/claroline/calendar/agenda.php?cidReq=' . $courseData['sysCode']);
         }
     }
     $output = '';
     //$output .= '<div class="calendar">'.$this->ajaxMiniCalendar($agendaItemList).'</div>';
     $output .= '<div class="details">' . "\n" . '<dl>' . "\n";
     if ($courseDigestList) {
         foreach ($courseDigestList as $agendaItem) {
             $output .= '<dt>' . "\n" . '<h2>' . claro_html_localised_date(get_locale('dateFormatLong'), strtotime($agendaItem['date'])) . '</h2>' . "\n" . '</dt>' . "\n";
             foreach ($agendaItem['eventList'] as $agendaEvent) {
                 $output .= '<dd>' . '<b>' . $agendaEvent['content'] . '</b>' . "\n" . (!empty($agendaEvent['hour']) ? ' &ndash; ' . ucfirst(strftime(get_locale('timeNoSecFormat'), strtotime($agendaEvent['hour']))) : '') . (!empty($agendaEvent['location']) ? ' | ' . $agendaEvent['location'] : '') . ' (<a href="' . $agendaEvent['url'] . '#item' . $agendaEvent['id'] . '">' . get_lang('more details') . '</a>)' . "\n" . '</dd>' . "\n";
             }
         }
     } else {
         $output .= '<dt>' . "\n" . get_lang('No event to display') . "\n" . '</dt>' . "\n";
     }
     $output .= '' . '</dl>' . "\n" . '</div>' . "\n";
     return $output;
 }
Exemple #13
0
 public function load()
 {
     $tblNameList = claro_sql_get_main_tbl();
     $sql = "SELECT M.`label` AS `label`,\n" . "M.`script_url` AS `entry`,\n" . "M.`name` AS `name`,\n" . "M.`activation` AS `activation`,\n" . "D.`name` AS `dock`\n" . "FROM `" . $tblNameList['dock'] . "` AS D\n" . "LEFT JOIN `" . $tblNameList['module'] . "` AS M\n" . "ON D.`module_id` = M.`id`\n" . "ORDER BY D.`rank` ";
     $appletList = claro_sql_query_fetch_all_rows($sql);
     if ($appletList) {
         $dockAppletList = array();
         foreach ($appletList as $key => $applet) {
             if (!array_key_exists($applet['dock'], $dockAppletList)) {
                 $dockAppletList[$applet['dock']] = array();
             }
             $entryPath = get_module_path($applet['label']) . '/' . $applet['entry'];
             if (file_exists($entryPath)) {
                 $applet['path'] = $entryPath;
                 // $appletList[$key] = $applet;
                 $dockAppletList[$applet['dock']][] = $applet;
             }
         }
         $this->_dockAppletList = $dockAppletList;
     }
 }
Exemple #14
0
/**
 * Count the number of student in both the given course and the given class
 * @param string $course_id
 * @param int $class_id
 * @param bool $include_children recursively count students from subclasses
 * @return int
 */
function class_get_number_of_users_in_course($course_id, $class_id, $include_children = true)
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_class_user = $tbl_mdb_names['rel_class_user'];
    $tbl_class = $tbl_mdb_names['class'];
    $tbl_course_user = $tbl_mdb_names['rel_course_user'];
    $sqlCourseId = Claroline::getDatabase()->quote($course_id);
    //1- get class users number
    $sqlcount = "SELECT COUNT(clu.`user_id`) AS qty_user\n                 FROM `{$tbl_class_user}` AS clu\n                 INNER JOIN `{$tbl_course_user}` AS cu \n                 ON `cu`.`user_id` = `clu`.`user_id`\n                 AND `cu`.`code_cours` = {$sqlCourseId}\n                 WHERE clu.`class_id` = " . (int) $class_id;
    $qty_user = Claroline::getDatabase()->query($sqlcount)->setFetchMode(Database_ResultSet::FETCH_VALUE)->fetch();
    if ($include_children) {
        $sql = "SELECT `id`\n                FROM `" . $tbl_class . "`\n                WHERE `class_parent_id`=" . (int) $class_id;
        $subClassesList = Claroline::getDatabase()->query($sql);
        //2- recursive call to get subclasses'users too
        foreach ($subClassesList as $subClass) {
            $qty_user += class_get_number_of_users_in_course($subClass['id'], true);
        }
    }
    //3- return result of counts and recursive calls
    return $qty_user;
}
Exemple #15
0
 /**
  * 
  * @param string $cid id(code) of the course
  * @param mixed $database Database_Connection instance or null, if null, the default database connection will be used
  */
 public function __construct($cid = null, $database = null)
 {
     $this->cid = is_null($cid) ? claro_get_current_course_id() : $cid;
     $this->database = is_null($database) ? Claroline::getDatabase() : $database;
     $this->course = new Claro_course($cid);
     $this->course->load();
     $this->tables = claro_sql_get_main_tbl();
 }
Exemple #16
0
function class_exist()
{
    $tbl = claro_sql_get_main_tbl();
    $sql = "\n        SELECT id FROM `" . $tbl['class'] . "`";
    return claro_sql_query_fetch_all($sql);
}
/**
 * Upgrade assignment tool to 1.6
 */
function assignment_upgrade_to_16($course_code)
{
    global $currentCourseVersion, $currentcoursePathSys, $currentCourseCreationDate;
    global $_uid;
    $versionRequiredToProceed = '/^1.5/';
    $tool = 'CLWRK';
    $currentCourseDbNameGlu = claro_get_course_db_name_glued($course_code);
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_rel_course_user = $tbl_mdb_names['rel_course_user'];
    $tbl_course_tool = $tbl_mdb_names['tool'];
    if (preg_match($versionRequiredToProceed, $currentCourseVersion)) {
        switch ($step = get_upgrade_status($tool, $course_code)) {
            case 1:
                /**
                 * STEP 1 Create new work table
                 */
                $sql_step1[] = "CREATE TABLE IF NOT EXISTS `" . $currentCourseDbNameGlu . "wrk_assignment` (\n                `id` int(11) NOT NULL auto_increment,\n                `title` varchar(200) NOT NULL default '',\n                `description` text NOT NULL,\n                `visibility` enum('VISIBLE','INVISIBLE') NOT NULL default 'VISIBLE',\n                `def_submission_visibility` enum('VISIBLE','INVISIBLE') NOT NULL default 'VISIBLE',\n                `assignment_type` enum('INDIVIDUAL','GROUP') NOT NULL default 'INDIVIDUAL',\n                `authorized_content` enum('TEXT','FILE','TEXTFILE') NOT NULL default 'FILE',\n                `allow_late_upload` enum('YES','NO') NOT NULL default 'YES',\n                `start_date` datetime NOT NULL default '0000-00-00 00:00:00',\n                `end_date` datetime NOT NULL default '0000-00-00 00:00:00',\n                `prefill_text` text NOT NULL,\n                `prefill_doc_path` varchar(200) NOT NULL default '',\n                `prefill_submit` enum('ENDDATE','AFTERPOST') NOT NULL default 'ENDDATE',\n                PRIMARY KEY  (`id`)\n                ) ENGINE=MyISAM";
                /*
                            $sql_step1[] = "UPDATE `".$currentCourseDbNameGlu."wrk_assignment`
                                SET
                                `end_date` = '".date('Y-m-d H:i:00', mktime( date('H'),date('i'),0,date('m'), date('d'), date('Y')+1 ) )."'
                                WHERE `end_date` = '0000-00-00 00:00:00'
                                ";
                */
                $sql_step1[] = "CREATE TABLE IF NOT EXISTS `" . $currentCourseDbNameGlu . "wrk_submission` (\n                `id` int(11) NOT NULL auto_increment,\n                `assignment_id` int(11) default NULL,\n                `parent_id` int(11) default NULL,\n                `user_id`  int(11) default NULL ,\n                `group_id` int(11) default NULL,\n                `title` varchar(200) NOT NULL default '',\n                `visibility` enum('VISIBLE','INVISIBLE') default 'VISIBLE',\n                `creation_date` datetime NOT NULL default '0000-00-00 00:00:00',\n                `last_edit_date` datetime NOT NULL default '0000-00-00 00:00:00',\n                `authors` varchar(200) NOT NULL default '',\n                `submitted_text` text NOT NULL,\n                `submitted_doc_path` varchar(200) NOT NULL default '',\n                `private_feedback` text,\n                `original_id` int(11) default NULL,\n                `score` smallint(3) default NULL,\n                PRIMARY KEY  (`id`)\n                ) ENGINE=MyISAM";
                if (!upgrade_apply_sql($sql_step1)) {
                    return $step;
                }
                $step = set_upgrade_status($tool, 2, $course_code);
            case 2:
                /**
                 * STEP 2 : Create a new assignment
                 */
                // get work intro in tool
                $sql_work_intro = "SELECT ti.texte_intro\n                                    FROM `" . $currentCourseDbNameGlu . "tool_list` tl,\n                                         `" . $currentCourseDbNameGlu . "tool_intro` ti,\n                                         `" . $tbl_course_tool . "` ct\n                                    WHERE ti.id = tl.id\n                                        AND tl.tool_id =  ct.id\n                                        AND ct.claro_label = 'CLWRK___'";
                $work_intro = claro_sql_query_get_single_value($sql_work_intro);
                if ($work_intro === FALSE) {
                    $work_intro = '';
                }
                $sql_step2[] = "INSERT INTO `" . $currentCourseDbNameGlu . "wrk_assignment`\n                    SET `id` = 1,\n                    `title` = 'Assignments',\n                    `description`= '" . mysql_real_escape_string($work_intro) . "',\n                    `visibility` = 'VISIBLE',\n                    `def_submission_visibility` = 'VISIBLE',\n                    `assignment_type` = 'INDIVIDUAL',\n                    `authorized_content` = 'FILE',\n                    `allow_late_upload` = 'NO',\n                    `start_date` = '" . $currentCourseCreationDate . "',\n                    `end_date` = DATE_ADD(NOW(),INTERVAL 1 YEAR),\n                    `prefill_text` = '',\n                    `prefill_doc_path` = '',\n                    `prefill_submit` = 'ENDDATE' ";
                if (!upgrade_apply_sql($sql_step2)) {
                    return $step;
                }
                $step = set_upgrade_status($tool, 3, $course_code);
            case 3:
                /**
                 * STEP 3 : Add old works as submissions of new assignment
                 */
                // get course manager of the course
                $sql_get_id_of_one_teacher = "SELECT `user_id` `uid` " . " FROM `" . $tbl_rel_course_user . "` " . " WHERE `code_cours` = '" . $course_code . "' LIMIT 1";
                $teacher = claro_sql_query_fetch_all($sql_get_id_of_one_teacher);
                $teacher_uid = $teacher[0]['uid'];
                // if no course manager, you are enrolled in as
                if (!is_numeric($teacher_uid)) {
                    $teacher_uid = $_uid;
                    $sql_set_teacher = "INSERT INTO `" . $tbl_rel_course_user . "`\n                                        SET `user_id` = '" . $teacher_uid . "'\n                                             , `code_cours` = '" . $course_code . "'\n                                             , `role` = 'Course missing manager';";
                    if (!claro_sql_query($sql_set_teacher)) {
                        return $step;
                    }
                    log_message('Warning : Course ' . $course_code . ' has no teacher, you are enrolled in as course manager.');
                }
                // add old work in submission of course manager
                $sql_step3[] = "INSERT IGNORE INTO `" . $currentCourseDbNameGlu . "wrk_submission`\n                 (assignment_id,user_id,title,visibility,authors,submitted_text,submitted_doc_path)\n                 SELECT 1, '" . $teacher_uid . "', titre, IF(accepted,'VISIBLE','INVISIBLE'), auteurs, description, url\n                    FROM `" . $currentCourseDbNameGlu . "assignment_doc`";
                if (!upgrade_apply_sql($sql_step3)) {
                    return $step;
                }
                $step = set_upgrade_status($tool, 4, $course_code);
            case 4:
                /**
                 * STEP 4 : Update document path of submissions
                 */
                $sql_step4[] = "UPDATE `" . $currentCourseDbNameGlu . "wrk_submission`\n                                SET submitted_doc_path = REPLACE (`submitted_doc_path` ,'work/','')";
                if (!upgrade_apply_sql($sql_step4)) {
                    return $step;
                }
                $step = set_upgrade_status($tool, 5, $course_code);
            case 5:
                /**
                 * STEP 5 : Create new folder to store assig_1 and move old old work documents in it
                 */
                // create new folder
                $work_dirname = $currentcoursePathSys . 'work/';
                $assignment_dirname = $work_dirname . 'assig_1/';
                if (!is_dir($assignment_dirname)) {
                    if (!@mkdir($assignment_dirname, CLARO_FILE_PERMISSIONS)) {
                        log_message('Error: Cannot create ' . $assignment_dirname);
                        return $step;
                    }
                }
                // move assignment from work to work/assig_1
                if (is_dir($work_dirname)) {
                    if ($handle = opendir($work_dirname)) {
                        while (FALSE !== ($file = readdir($handle))) {
                            if (is_dir($work_dirname . $file)) {
                                continue;
                            }
                            if (@rename($work_dirname . $file, $assignment_dirname . $file) === FALSE) {
                                log_message('Error: Cannot rename ' . $work_dirname . $file . ' to ' . $assignment_dirname . $file);
                                return $step;
                            }
                        }
                        closedir($handle);
                    }
                }
                $step = set_upgrade_status($tool, 6, $course_code);
            case 6:
                /**
                 * STEP 6 Drop deprecated assignment_doc
                 */
                // $sql_step6[] = "DROP TABLE IF EXISTS `".$currentCourseDbNameGlu."assignment_doc`";
                // if ( ! upgrade_apply_sql($sql_step6) ) return $step;
                $step = set_upgrade_status($tool, 0, $course_code);
            default:
                return $step;
        }
        // end switch
    }
    return false;
}
Exemple #18
0
/**
 * Return if course status is enable
 */
function claro_is_course_enable()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_course = $tbl_mdb_names['course'];
    $courseId = claro_get_current_course_id();
    $curdate = claro_mktime();
    if (claro_is_course_manager()) {
        $sql = " SELECT c.`code`\n             FROM `" . $tbl_course . "` c\n            WHERE  (c.`status` != 'trash')\n              AND c.`code` = '" . $courseId . "';";
    } else {
        $sql = " SELECT c.`code`\n           FROM `" . $tbl_course . "` c\n           WHERE (c.`status` = 'enable'\n                   OR (c.`status` = 'date'\n                       AND (UNIX_TIMESTAMP(`creationDate`) <= '" . $curdate . "'\n                            OR `creationDate` IS NULL OR UNIX_TIMESTAMP(`creationDate`) = 0\n                           )\n                       AND ('" . $curdate . "' <= UNIX_TIMESTAMP(`expirationDate`)\n                            OR `expirationDate` IS NULL\n                           )\n                      )\n                 )\n                 AND c.`code` = '" . $courseId . "';";
    }
    $result = claro_sql_query_get_single_value($sql);
    if (isset($result) or claro_is_platform_admin()) {
        $return = true;
    } else {
        $return = false;
    }
    return $return;
}
Exemple #19
0
/**
 * Return course list which have an unexisting category as parent
 *
 * @author Christophe Gesché <*****@*****.**>
 * @since 1.8
 *
 * @return array('Course code'=>string, 'Unknow faculty'=>string)
 */
function checkCourseOwnance()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $sql = "SELECT c.code    AS `Course code`,\n                   c.faculte AS `Unknow faculty`\n        FROM  `" . $tbl_mdb_names['course'] . "`       AS c\n        LEFT JOIN  `" . $tbl_mdb_names['category'] . "` AS f\n        ON c.FACULTE = f.code\n        WHERE f.id IS null ";
    if (false !== ($res = claro_sql_query_fetch_all($sql))) {
        return $res;
    } else {
        return claro_failure::set_failure('QUERY_ERROR_' . __LINE__);
    }
}
Exemple #20
0
/**
 * Clean status of a tool
 *
 * @param string course_code
 *
 * @return integer status value
 *
 * @since  1.7
 */
function clean_upgrade_status($course_code = null)
{
    // get table name
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_upgrade_status = $tbl_mdb_names['upgrade_status'];
    // course_code empty
    if (is_null($course_code)) {
        $course_code = '';
    }
    // delete all status for this course
    $sql = " DELETE FROM `" . $tbl_upgrade_status . "`\n             WHERE cid = '" . $course_code . "' ";
    return claro_sql_query($sql);
}
Exemple #21
0
/**
 * to know if user is registered to a course or not
 *
 * @copyright   (c) 2001-2011, Universite catholique de Louvain (UCL)
 * @param  int     id of user in DB
 * @param  int     id of course in DB
 * @return boolean true if user is enrolled false otherwise
 */
function is_registered_to($user_id, $course_id)
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_rel_course_user = $tbl_mdb_names['rel_course_user'];
    $sql = "SELECT count(*) `user_reg`\n                 FROM `" . $tbl_rel_course_user . "`\n                 WHERE `code_cours` = '" . claro_sql_escape($course_id) . "' AND `user_id` = '" . (int) $user_id . "'";
    $res = claro_sql_query_fetch_all($sql);
    return (bool) ($res[0]['user_reg'] > 0);
}
Exemple #22
0
 * @package     ADMIN
 * @author      Claro Team <*****@*****.**>
 */
require '../../inc/claro_init_global.inc.php';
//SECURITY CHECK
if (!claro_is_user_authenticated()) {
    claro_disp_auth_form();
}
if (!claro_is_platform_admin()) {
    claro_die(get_lang('Not allowed'));
}
//DECLARE NEEDED LIBRARIES
require_once get_path('incRepositorySys') . '/lib/pager.lib.php';
require_once get_path('incRepositorySys') . '/lib/module/manage.lib.php';
//SQL table name
$tbl_name = claro_sql_get_main_tbl();
$tbl_module = $tbl_name['module'];
$tbl_dock = $tbl_name['dock'];
$dialogBox = new DialogBox();
if (isset($_REQUEST['dock'])) {
    $dockList = get_dock_list('applet');
    $dock = $_REQUEST['dock'];
    $dockName = isset($dockList[$dock]) ? $dockList[$dock] : $dock;
    $nameTools = get_lang('Dock') . ' : ' . $dockName;
} else {
    $dock = null;
    $dialogBox->error(get_lang('No dock selected'));
    $nameTools = get_lang('Dock');
}
ClaroBreadCrumbs::getInstance()->prepend(get_lang('Module list'), get_path('rootAdminWeb') . 'module/module_list.php');
ClaroBreadCrumbs::getInstance()->prepend(get_lang('Administration'), get_path('rootAdminWeb'));
Exemple #23
0
 public function getIterator()
 {
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_courses = $tbl_mdb_names['course'];
     $upperKeyword = addslashes(strtoupper($this->keyword));
     $sql = "SELECT\n                c.code                  AS courseId,\n                c.code                  AS sysCode,\n                c.cours_id              AS id,\n                c.isSourceCourse        AS isSourceCourse,\n                c.sourceCourseId        AS sourceCourseId,\n                c.intitule              AS name,\n                c.administrativeNumber  AS officialCode,\n                c.administrativeNumber  AS administrativeNumber,\n                c.directory             AS path,\n                c.dbName                AS dbName,\n                c.titulaires            AS titular,\n                c.email                 AS email,\n                c.language              AS language,\n                c.extLinkUrl            AS extLinkUrl,\n                c.extLinkName           AS extLinkName,\n                c.visibility            AS visibility,\n                c.access                AS access,\n                c.registration          AS registration,\n                c.registrationKey       AS registrationKey,\n                c.diskQuota             AS diskQuota,\n                UNIX_TIMESTAMP(c.creationDate)      AS publicationDate,\n                UNIX_TIMESTAMP(c.expirationDate)    AS expirationDate,\n                c.status                AS status,\n                c.userLimit             AS userLimit\n                \n                FROM `" . $tbl_courses . "` AS c\n                \n                WHERE UPPER(administrativeNumber) LIKE '%" . $upperKeyword . "%'\n                OR UPPER(intitule) LIKE '%" . $upperKeyword . "%'\n                OR UPPER(titulaires) LIKE '%" . $upperKeyword . "%'\n                \n                ORDER BY " . $this->orderBy . " ASC";
     $result = Claroline::getDatabase()->query($sql);
     return new CourseListIterator($result);
 }
Exemple #24
0
/**
 * Prepares the sql request to select courses in database.
 *
 * @return string $sql
 */
function prepare_get_filtred_course_list()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $sqlFilter = array();
    // Prepare filter deal with KEY WORDS classification call
    if (isset($_SESSION['admin_course_search'])) {
        $sqlFilter[] = "(  co.`intitule`  LIKE '%" . claro_sql_escape(pr_star_replace($_SESSION['admin_course_search'])) . "%'" . "\n" . "   OR co.`administrativeNumber` LIKE '%" . claro_sql_escape(pr_star_replace($_SESSION['admin_course_search'])) . "%'" . "\n" . ")";
    }
    // Deal with ADVANCED SEARCH parmaters call
    if (isset($_SESSION['admin_course_intitule']) && !empty($_SESSION['admin_course_intitule'])) {
        $sqlFilter[] = "(co.`intitule` LIKE '%" . claro_sql_escape(pr_star_replace($_SESSION['admin_course_intitule'])) . "%')";
    }
    if (isset($_SESSION['admin_course_code']) && !empty($_SESSION['admin_course_code'])) {
        $sqlFilter[] = "(co.`administrativeNumber` LIKE '%" . claro_sql_escape(pr_star_replace($_SESSION['admin_course_code'])) . "%')";
    }
    if (isset($_SESSION['admin_course_language'])) {
        $sqlFilter[] = "(co.`language` = '" . claro_sql_escape($_SESSION['admin_course_language']) . "')";
    }
    if (isset($_SESSION['admin_course_visibility'])) {
        if ($_SESSION['admin_course_visibility'] == 'invisible') {
            $sqlFilter[] = "co.`visibility`='INVISIBLE'";
        } elseif ($_SESSION['admin_course_visibility'] == 'visible') {
            $sqlFilter[] = "co.`visibility`='VISIBLE'";
        }
    }
    if (isset($_SESSION['admin_course_access'])) {
        if ($_SESSION['admin_course_access'] == 'public') {
            $sqlFilter[] = "co.`access`='public'";
        } elseif ($_SESSION['admin_course_access'] == 'private') {
            $sqlFilter[] = "co.`access`='private'";
        } elseif ($_SESSION['admin_course_access'] == 'platform') {
            $sqlFilter[] = "co.`access`='platform'";
        }
    }
    if (isset($_SESSION['admin_course_subscription'])) {
        if ($_SESSION['admin_course_subscription'] == 'allowed') {
            $sqlFilter[] = "co.`registration`='OPEN'";
        } elseif ($_SESSION['admin_course_subscription'] == 'denied') {
            $sqlFilter[] = "co.`registration`='CLOSE'";
        } elseif ($_SESSION['admin_course_subscription'] == 'key') {
            $sqlFilter[] = "co.`registration`='OPEN' AND CHAR_LENGTH(co.`registrationKey`) != 0";
        }
    }
    // Create the WHERE clauses
    $sqlFilter = sizeof($sqlFilter) ? "WHERE " . implode(" AND ", $sqlFilter) : "";
    // Build the complete SQL request
    $sql = "SELECT co.`cours_id`      AS `id`, " . "\n" . "co.`administrativeNumber` AS `officialCode`, " . "\n" . "co.`intitule`             AS `intitule`, " . "\n" . "co.`code`                 AS `sysCode`, " . "\n" . "co.`sourceCourseId`       AS `sourceCourseId`, " . "\n" . "co.`isSourceCourse`       AS `isSourceCourse`, " . "\n" . "co.`visibility`           AS `visibility`, " . "\n" . "co.`access`               AS `access`, " . "\n" . "co.`registration`         AS `registration`, " . "\n" . "co.`registrationKey`      AS `registrationKey`, " . "\n" . "co.`directory`            AS `repository`, " . "\n" . "co.`status`               AS `status` " . "\n" . "FROM  `" . $tbl_mdb_names['course'] . "` AS co " . "\n" . $sqlFilter;
    return $sql;
}
/**
 * Move tracking data from old tables to new ones.
 *
 * @return upgrade status
 */
function upgrade_main_database_tracking_data_to_19()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tool = 'MAIN_TRACKING_DATA_19';
    switch ($step = get_upgrade_status($tool)) {
        case 1:
            // drop id to be able to recreate it with correct autoincrement values at last step
            $sql = "ALTER TABLE `" . $tbl_mdb_names['tracking_event'] . "` DROP `id`";
            if (upgrade_sql_query($sql)) {
                $step = set_upgrade_status($tool, $step + 1);
            } else {
                return $step;
            }
            unset($sql);
        case 2:
            // get total number of rows in track_e_login
            $sql = "SELECT COUNT(*)\n                        FROM `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "track_e_login`";
            $tableRows = (int) claro_sql_query_fetch_single_value($sql);
            $recoveredOffset = UpgradeTrackingOffset::retrieve();
            // get a subgroup of 250 rows and insert group by group in tracking_event table
            for ($offset = $recoveredOffset; $offset < $tableRows; $offset += 250) {
                // we have to store offset to start again from it if something failed
                UpgradeTrackingOffset::store($offset);
                $query = "SELECT `login_id`, `login_user_id`, `login_date`, `login_ip`\n                            FROM `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "track_e_login`\n                        ORDER BY `login_date`, `login_id`\n                           LIMIT " . $offset . ", 250";
                // then copy these 250 rows to tracking_event
                $eventList = claro_sql_query_fetch_all_rows($query);
                // build query to insert all 250 rows
                $sql = "INSERT INTO `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "tracking_event`\n                        ( `user_id`, `date`, `type`, `data` )\n                        VALUES\n                        ";
                //inject former data into new table structure
                foreach ($eventList as $event) {
                    $sql .= "(" . (int) $event['login_user_id'] . ",'" . claro_sql_escape($event['login_date']) . "','user_login','" . claro_sql_escape(serialize(array('ip' => $event['login_ip']))) . "'),\n";
                }
                unset($eventList);
                if (upgrade_sql_query(rtrim($sql, ",\n"))) {
                    unset($sql);
                    //continue;
                } else {
                    return $step;
                }
            }
            UpgradeTrackingOffset::reset();
            $step = set_upgrade_status($tool, $step + 1);
        case 3:
            // get total number of rows in track_e_login
            $sql = "SELECT COUNT(*)\n                        FROM `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "track_e_open`";
            $tableRows = (int) claro_sql_query_fetch_single_value($sql);
            $recoveredOffset = UpgradeTrackingOffset::retrieve();
            // get a subgroup of 250 rows and insert group by group in tracking_event table
            for ($offset = $recoveredOffset; $offset < $tableRows; $offset += 250) {
                // we have to store offset to start again from it if something failed
                UpgradeTrackingOffset::store($offset);
                $query = "SELECT `open_id`, `open_date`\n                            FROM `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "track_e_open`\n                        ORDER BY `open_date`, `open_id`\n                           LIMIT " . $offset . ", 250";
                // then copy these 250 rows to tracking_event
                $eventList = claro_sql_query_fetch_all_rows($query);
                // build query to insert all 250 rows
                $sql = "INSERT INTO `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "tracking_event`\n                        ( `user_id`, `date`, `type`, `data` )\n                        VALUES\n                        ";
                //inject former data into new table structure
                foreach ($eventList as $event) {
                    $sql .= "(NULL,'" . claro_sql_escape($event['open_date']) . "','platform_access',''),\n";
                }
                unset($eventList);
                if (upgrade_sql_query(rtrim($sql, ",\n"))) {
                    unset($sql);
                    //continue;
                } else {
                    return $step;
                }
            }
            UpgradeTrackingOffset::reset();
            $step = set_upgrade_status($tool, $step + 1);
        case 4:
            // order table using dates then recreate primary key with correct autoincrement value
            $sqlForUpdate[] = "ALTER TABLE `" . $tbl_mdb_names['tracking_event'] . "`  ORDER BY `date`";
            $sqlForUpdate[] = "ALTER TABLE `" . $tbl_mdb_names['tracking_event'] . "` ADD `id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST";
            if (upgrade_apply_sql($sqlForUpdate)) {
                $step = set_upgrade_status($tool, $step + 1);
            } else {
                return $step;
            }
        case 5:
            //drop deprecated tracking tables
            $sqlForUpdate[] = "DROP TABLE IF EXISTS `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "track_e_open`";
            $sqlForUpdate[] = "DROP TABLE IF EXISTS `" . get_conf('statsDbName') . '`.`' . get_conf('statsTblPrefix') . "track_e_login`";
            // we should probably keep this table as it may be usefull for history purpose.  By the way it is not used in
            // any tracking interface.
            //$sqlForUpdate[] = "DROP TABLE IF EXISTS `" . get_conf( 'mainTblPrefix' ) . "track_e_default`";
            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;
}
Exemple #26
0
 /**
  * Courses are often identified through their code (sysCode).  But
  * sometimes their identifier (integer) can be useful.  This
  * method permits to easily get the id of a course based on
  * its code.
  *
  * @param string    course code (sysCode)
  * @return int      course identifier
  * @since 1.10
  */
 public static function getIdFromCode($code)
 {
     // Declare needed tables
     $tbl_mdb_names = claro_sql_get_main_tbl();
     $tbl_course = $tbl_mdb_names['course'];
     $sql = "SELECT c.cours_id AS id\n                \n                FROM `" . $tbl_course . "` AS c\n                WHERE c.code = '" . $code . "'";
     if ($result = claro_sql_query_get_single_row($sql)) {
         return $result['id'];
     } else {
         return null;
     }
 }
Exemple #27
0
/**
 * 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;
}
Exemple #28
0
 protected static function registerUser($userAttrList, $uid = null)
 {
     $preparedList = array();
     // Map database fields
     $dbFieldToClaroMap = array('nom' => 'lastname', 'prenom' => 'firstname', 'username' => 'loginName', 'email' => 'email', 'officialCode' => 'officialCode', 'phoneNumber' => 'phoneNumber', 'isCourseCreator' => 'isCourseCreator', 'authSource' => 'authSource');
     // Do not overwrite username and authsource for an existing user !!!
     if (!is_null($uid)) {
         unset($dbFieldToClaroMap['username']);
         unset($dbFieldToClaroMap['authSource']);
     }
     foreach ($dbFieldToClaroMap as $dbFieldName => $claroAttribName) {
         if (isset($userAttrList[$claroAttribName]) && !is_null($userAttrList[$claroAttribName])) {
             $preparedList[] = $dbFieldName . ' = ' . Claroline::getDatabase()->quote($userAttrList[$claroAttribName]);
         }
     }
     if (empty($preparedList)) {
         return false;
     }
     $tbl = claro_sql_get_main_tbl();
     $sql = ($uid ? 'UPDATE' : 'INSERT INTO') . " `{$tbl['user']}`\n" . "SET " . implode(",\n", $preparedList) . "\n" . ($uid ? "WHERE  user_id = " . (int) $uid : '');
     Claroline::getDatabase()->exec($sql);
     if (!$uid) {
         $uid = Claroline::getDatabase()->insertId();
     }
     return $uid;
 }
Exemple #29
0
                set_module_visibility_in_course($toolId, $_cid, true);
            }
        }
    }
}
/*---------------------------------------------------------------------------
  Course / tool relation initialisation
 ---------------------------------------------------------------------------*/
// if the requested tool is different from the current tool in session
// (special request can come from the tool id, or the tool label)
if ($tidReq && $tidReq != $_SESSION['_tid'] || $tlabelReq && (!isset($_SESSION['_courseTool']['label']) || $tlabelReq != $_SESSION['_courseTool']['label'])) {
    $tidReset = true;
}
if ($tidReset || $cidReset) {
    if (($tidReq || $tlabelReq) && $_cid) {
        $tbl_mdb_names = claro_sql_get_main_tbl();
        $tbl_tool = $tbl_mdb_names['tool'];
        $sql = " SELECT ctl.id                  AS id            ,\n                      pct.id                    AS toolId       ,\n                      pct.claro_label           AS label         ,\n                      ctl.script_name           AS name          ,\n                      ctl.visibility            AS visibility    ,\n                      pct.icon                  AS icon          ,\n                      pct.access_manager        AS access_manager,\n                      pct.script_url            AS url\n\n                   FROM `" . $_course['dbNameGlu'] . "tool_list` ctl,\n                    `" . $tbl_tool . "`  pct\n\n               WHERE `ctl`.`tool_id` = `pct`.`id`\n                 AND (`ctl`.`id`      = '" . (int) $tidReq . "'\n                       OR   (" . (int) is_null($tidReq) . " AND pct.claro_label = '" . claro_sql_escape($tlabelReq) . "')\n                     )";
        // Note : 'ctl' stands for  'course tool list' and  'pct' for 'platform course tool'
        $_courseTool = claro_sql_query_get_single_row($sql);
        if (is_array($_courseTool)) {
            $_tid = $_courseTool['id'];
            $_mainToolId = $_courseTool['toolId'];
        } else {
            $activatedModules = get_module_label_list(true);
            if (!in_array($tlabelReq, $activatedModules)) {
                exit('WARNING !! Undefined Tlabel or Tid: your script declare ' . 'be a tool wich is not registred at line ' . __LINE__ . '.  ' . 'Please contact your platform administrator.');
            } else {
                $_tid = null;
                $_mainToolId = null;
                $_courseTool = null;
Exemple #30
0
/**
 * Get the list of all installable course tool modules from kernel
 * @author Frederic Minne <*****@*****.**>
 */
function get_course_installable_tool_list()
{
    $tbl_mdb_names = claro_sql_get_main_tbl();
    $tbl_courseTool = $tbl_mdb_names['tool'];
    $sql = "SELECT id, def_access, def_rank, claro_label, add_in_course " . "FROM `" . $tbl_courseTool . "` ";
    $list = claro_sql_query_fetch_all_rows($sql);
    return $list;
}