Exemplo n.º 1
0
 /**
  * Publishes a learnpath. This basically means show or hide the learnpath
  * on the course homepage
  * Can be used as abstract
  * @param	integer	Learnpath ID
  * @param	string	New visibility
  */
 function toggle_publish($lp_id, $set_visibility = 'v')
 {
     //if($this->debug>0){error_log('New LP - In learnpath::toggle_publish()',0);}
     $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
     $sql = "SELECT * FROM {$tbl_lp} where id={$lp_id}";
     $result = Database::query($sql, __FILE__, __LINE__);
     $row = Database::fetch_array($result);
     $name = domesticate($row['name']);
     if ($set_visibility == 'i') {
         $s = $name . " " . get_lang('_no_published');
         $dialogBox = $s;
         $v = 0;
     }
     if ($set_visibility == 'v') {
         $s = $name . " " . get_lang('_published');
         $dialogBox = $s;
         $v = 1;
     }
     $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
     $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id;
     $sql = "SELECT * FROM {$tbl_tool} where name='{$name}' and image='scormbuilder.gif' and link LIKE '{$link}%'";
     $result = Database::query($sql, __FILE__, __LINE__);
     $num = Database::num_rows($result);
     $row2 = Database::fetch_array($result);
     //if($this->debug>2){error_log('New LP - '.$sql.' - '.$num,0);}
     if ($set_visibility == 'i' && $num > 0) {
         $sql = "DELETE FROM {$tbl_tool} WHERE (name='{$name}' and image='scormbuilder.gif' and link LIKE '{$link}%')";
     } elseif ($set_visibility == 'v' && $num == 0) {
         $sql = "INSERT INTO {$tbl_tool} (name, link, image, visibility, admin, address, added_tool) VALUES ('{$name}','newscorm/lp_controller.php?action=view&lp_id={$lp_id}','scormbuilder.gif','{$v}','0','pastillegris.gif',0)";
     } else {
         //parameter and database incompatible, do nothing
     }
     $result = Database::query($sql, __FILE__, __LINE__);
     //if($this->debug>2){error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql,0);}
 }
 /**
  * This method is the constructor for the learnpathList. It gets a list of available learning paths from
  * the database and creates the learnpath objects. This list depends on the user that is connected
  * (only displays) items if he has enough permissions to view them.
  * @param	integer	$user_id
  * @param	string	$course_code Optional course code (otherwise we use api_get_course_id())
  * @param   int		$session_id Optional session id (otherwise we use api_get_session_id())
  * @param   string  $order_by
  * @param   string  $check_publication_dates
  * @param   int     $categoryId
  *
  * @return	void
  */
 public function __construct($user_id, $course_code = '', $session_id = null, $order_by = null, $check_publication_dates = false, $categoryId = null)
 {
     $course_info = api_get_course_info($course_code);
     $lp_table = Database::get_course_table(TABLE_LP_MAIN);
     $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
     $this->course_code = $course_code;
     $this->user_id = $user_id;
     $course_id = $course_info['real_id'];
     if (empty($course_id)) {
         return false;
     }
     // Condition for the session.
     if (isset($session_id)) {
         $session_id = intval($session_id);
     } else {
         $session_id = api_get_session_id();
     }
     $condition_session = api_get_session_condition($session_id, true, true);
     $order = "ORDER BY display_order ASC, name ASC";
     if (isset($order_by)) {
         $order = Database::parse_conditions(array('order' => $order_by));
     }
     $now = api_get_utc_datetime();
     $time_conditions = '';
     if ($check_publication_dates) {
         $time_conditions = " AND (\n                (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '{$now}' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '{$now}' )  OR\n                (publicated_on <> '0000-00-00 00:00:00' AND publicated_on < '{$now}' AND expired_on = '0000-00-00 00:00:00') OR\n                (publicated_on = '0000-00-00 00:00:00' AND expired_on <> '0000-00-00 00:00:00' AND expired_on > '{$now}') OR\n                (publicated_on = '0000-00-00 00:00:00' AND expired_on = '0000-00-00 00:00:00' ))\n            ";
     }
     if (!empty($categoryId)) {
         $categoryId = intval($categoryId);
         $categoryFilter = " AND category_id = {$categoryId}";
     } else {
         $categoryFilter = " AND (category_id = 0 OR category_id IS NULL) ";
     }
     $sql = "SELECT * FROM {$lp_table}\n                WHERE\n                    c_id = {$course_id}\n                    {$time_conditions}\n                    {$condition_session}\n                    {$categoryFilter}\n                {$order}\n                    ";
     $res = Database::query($sql);
     $names = array();
     while ($row = Database::fetch_array($res, 'ASSOC')) {
         // Use domesticate here instead of Database::escape_string because
         // it prevents ' to be slashed and the input (done by learnpath.class.php::toggle_visibility())
         // is done using domesticate()
         $myname = domesticate($row['name']);
         $mylink = 'newscorm/lp_controller.php?action=view&lp_id=' . $row['id'] . '&id_session=' . $session_id;
         $sql2 = "SELECT * FROM {$tbl_tool}\n                     WHERE\n                        c_id = {$course_id} AND (\n                            name='{$myname}' AND\n                            image='scormbuilder.gif' AND\n                            link LIKE '{$mylink}%'\n                      )";
         $res2 = Database::query($sql2);
         if (Database::num_rows($res2) > 0) {
             $row2 = Database::fetch_array($res2);
             $pub = $row2['visibility'];
         } else {
             $pub = 'i';
         }
         // Check if visible.
         $vis = api_get_item_visibility(api_get_course_info($course_code), 'learnpath', $row['id'], $session_id);
         if (!empty($row['created_on']) && $row['created_on'] != '0000-00-00 00:00:00') {
             $row['created_on'] = $row['created_on'];
         } else {
             $row['created_on'] = '';
         }
         if (!empty($row['modified_on']) && $row['modified_on'] != '0000-00-00 00:00:00') {
             $row['modified_on'] = $row['modified_on'];
         } else {
             $row['modified_on'] = '';
         }
         if (!empty($row['publicated_on']) && $row['publicated_on'] != '0000-00-00 00:00:00') {
             $row['publicated_on'] = $row['publicated_on'];
         } else {
             $row['publicated_on'] = '';
         }
         if (!empty($row['expired_on']) && $row['expired_on'] != '0000-00-00 00:00:00') {
             $row['expired_on'] = $row['expired_on'];
         } else {
             $row['expired_on'] = '';
         }
         $this->list[$row['id']] = array('lp_type' => $row['lp_type'], 'lp_session' => $row['session_id'], 'lp_name' => stripslashes($row['name']), 'lp_desc' => stripslashes($row['description']), 'lp_path' => $row['path'], 'lp_view_mode' => $row['default_view_mod'], 'lp_force_commit' => $row['force_commit'], 'lp_maker' => stripslashes($row['content_maker']), 'lp_proximity' => $row['content_local'], 'lp_encoding' => api_get_system_encoding(), 'lp_visibility' => $vis, 'lp_published' => $pub, 'lp_prevent_reinit' => $row['prevent_reinit'], 'seriousgame_mode' => $row['seriousgame_mode'], 'lp_scorm_debug' => $row['debug'], 'lp_display_order' => $row['display_order'], 'lp_preview_image' => stripslashes($row['preview_image']), 'autolaunch' => $row['autolaunch'], 'session_id' => $row['session_id'], 'created_on' => $row['created_on'], 'modified_on' => $row['modified_on'], 'publicated_on' => $row['publicated_on'], 'expired_on' => $row['expired_on'], 'subscribe_users' => $row['subscribe_users']);
         $names[$row['name']] = $row['id'];
     }
     $this->alpha_list = asort($names);
 }
Exemplo n.º 3
0
 /**
  * Publishes a learnpath. This basically means show or hide the learnpath
  * on the course homepage
  * Can be used as abstract
  * @param	integer	$lp_id Learnpath id
  * @param	string	$set_visibility New visibility (v/i - visible/invisible)
  * @return bool
  */
 public static function toggle_publish($lp_id, $set_visibility = 'v')
 {
     $course_id = api_get_course_int_id();
     $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
     $lp_id = intval($lp_id);
     $sql = "SELECT * FROM {$tbl_lp}\n                WHERE c_id = " . $course_id . " AND id = {$lp_id}";
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         $row = Database::fetch_array($result);
         $name = domesticate($row['name']);
         if ($set_visibility == 'i') {
             $s = $name . " " . get_lang('LearnpathNotPublished');
             $dialogBox = $s;
             $v = 0;
         }
         if ($set_visibility == 'v') {
             $s = $name . " " . get_lang('LearnpathPublished');
             $dialogBox = $s;
             $v = 1;
         }
     } else {
         return false;
     }
     $session_id = api_get_session_id();
     $session_condition = api_get_session_condition($session_id);
     $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
     $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '&id_session=' . $session_id;
     $sql = "SELECT * FROM {$tbl_tool}\n                WHERE\n                    c_id = " . $course_id . " AND\n                    link='{$link}' and\n                    image='scormbuilder.gif' and\n                    link LIKE '{$link}%'\n                    {$session_condition}\n                ";
     $result = Database::query($sql);
     $num = Database::num_rows($result);
     if ($set_visibility == 'i' && $num > 0) {
         $sql = "DELETE FROM {$tbl_tool}\n                    WHERE c_id = " . $course_id . " AND (link='{$link}' and image='scormbuilder.gif' {$session_condition})";
         Database::query($sql);
     } elseif ($set_visibility == 'v' && $num == 0) {
         $sql = "INSERT INTO {$tbl_tool} (category, c_id, name, link, image, visibility, admin, address, added_tool, session_id) VALUES\n            \t    ('authoring', {$course_id}, '{$name}', '{$link}', 'scormbuilder.gif', '{$v}', '0','pastillegris.gif', 0, {$session_id})";
         Database::query($sql);
         $insertId = Database::insert_id();
         if ($insertId) {
             $sql = "UPDATE {$tbl_tool} SET id = iid WHERE iid = {$insertId}";
             Database::query($sql);
         }
     } elseif ($set_visibility == 'v' && $num > 0) {
         $sql = "UPDATE {$tbl_tool} SET\n                        c_id = {$course_id},\n                        name = '{$name}',\n                        link = '{$link}',\n                        image = 'scormbuilder.gif',\n                        visibility = '{$v}',\n                        admin = '0',\n                        address = 'pastillegris.gif',\n                        added_tool = 0,\n                        session_id = {$session_id}\n            \t    WHERE\n            \t        c_id = " . $course_id . " AND\n            \t        (link='{$link}' and image='scormbuilder.gif' {$session_condition})\n                    ";
         Database::query($sql);
     } else {
         // Parameter and database incompatible, do nothing, exit.
         return false;
     }
 }
Exemplo n.º 4
0
 /**
  * Publishes a learnpath. This basically means show or hide the learnpath
  * on the course homepage
  * Can be used as abstract
  * @param	integer	Learnpath id
  * @param	string	New visibility (v/s - visible/invisible)
  */
 public static function toggle_publish($lp_id, $set_visibility = 'v')
 {
     //if ($this->debug > 0) { error_log('New LP - In learnpath::toggle_publish()', 0); }
     $course_id = api_get_course_int_id();
     $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
     $lp_id = Database::escape_string($lp_id);
     $sql = "SELECT * FROM {$tbl_lp} where c_id = " . $course_id . " AND id={$lp_id}";
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         $row = Database::fetch_array($result);
         $name = domesticate($row['name']);
         if ($set_visibility == 'i') {
             $s = $name . " " . get_lang('LearnpathNotPublished');
             $dialogBox = $s;
             $v = 0;
         }
         if ($set_visibility == 'v') {
             $s = $name . " " . get_lang('LearnpathPublished');
             $dialogBox = $s;
             $v = 1;
         }
     } else {
         return false;
     }
     $session_id = api_get_session_id();
     $session_condition = api_get_session_condition($session_id);
     $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
     $link = 'newscorm/lp_controller.php?action=view&lp_id=' . $lp_id . '&id_session=' . $session_id;
     $sql = "SELECT * FROM {$tbl_tool} WHERE c_id = " . $course_id . " AND link='{$link}' and image='scormbuilder.gif' and link LIKE '{$link}%' {$session_condition}";
     $result = Database::query($sql);
     $num = Database::num_rows($result);
     //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
     if ($set_visibility == 'i' && $num > 0) {
         $sql = "DELETE FROM {$tbl_tool} WHERE c_id = " . $course_id . " AND (link='{$link}' and image='scormbuilder.gif' {$session_condition})";
     } elseif ($set_visibility == 'v' && $num == 0) {
         $sql = "INSERT INTO {$tbl_tool} (c_id, name, link, image, visibility, admin, address, added_tool, session_id) VALUES\n            \t    ({$course_id}, '{$name}','{$link}','scormbuilder.gif','{$v}','0','pastillegris.gif',0, {$session_id})";
     } elseif ($set_visibility == 'v' && $num > 0) {
         $sql = "UPDATE {$tbl_tool} SET c_id = {$course_id}, name = '{$name}', link = '{$link}', image = 'scormbuilder.gif', visibility = '{$v}', admin = '0', address = 'pastillegris.gif', added_tool = 0, session_id = {$session_id}\n            \t    WHERE c_id = " . $course_id . " AND (link='{$link}' and image='scormbuilder.gif' {$session_condition})";
     } else {
         // Parameter and database incompatible, do nothing, exit.
         return false;
     }
     $result = Database::query($sql);
     //if ($this->debug > 2) { error_log('New LP - Leaving learnpath::toggle_visibility: '.$sql, 0); }
 }
Exemplo n.º 5
0
    /**
     * Publishes a learnpath. This basically means show or hide the learnpath
     * on the course homepage
     * Can be used as abstract
     * @param	integer	$lp_id Learnpath id
     * @param	string	$set_visibility New visibility (v/i - visible/invisible)
     * @return bool
     */
    public static function toggle_publish($lp_id, $set_visibility = 'v')
    {
        $course_id = api_get_course_int_id();
        $tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
        $lp_id = intval($lp_id);
        $sql = "SELECT * FROM $tbl_lp where c_id = ".$course_id." AND id=$lp_id";
        $result = Database::query($sql);
        if (Database::num_rows($result)) {
            $row = Database :: fetch_array($result);
            $name = domesticate($row['name']);
            if ($set_visibility == 'i') {
                $s = $name . " " . get_lang('LearnpathNotPublished');
                $dialogBox = $s;
                $v = 0;
            }
            if ($set_visibility == 'v') {
                $s = $name . " " . get_lang('LearnpathPublished');
                $dialogBox = $s;
                $v = 1;
            }
        } else {
            return false;
        }

        $session_id = api_get_session_id();
        $session_condition = api_get_session_condition($session_id);

        $tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
        $link = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id;
        $sql = "SELECT * FROM $tbl_tool
                WHERE
                    c_id = ".$course_id." AND
                    link='$link' and
                    image='scormbuilder.gif' and
                    link LIKE '$link%'
                    $session_condition
                ";
        $result = Database::query($sql);
        $num = Database :: num_rows($result);
        //if ($this->debug > 2) { error_log('New LP - '.$sql.' - '.$num, 0); }
        if (($set_visibility == 'i') && ($num > 0)) {
            $sql = "DELETE FROM $tbl_tool WHERE c_id = ".$course_id." AND (link='$link' and image='scormbuilder.gif' $session_condition)";
        } elseif (($set_visibility == 'v') && ($num == 0)) {
            $sql = "INSERT INTO $tbl_tool (c_id, name, link, image, visibility, admin, address, added_tool, session_id) VALUES
            	    ($course_id, '$name', '$link', 'scormbuilder.gif', '$v', '0','pastillegris.gif', 0, $session_id)";
        } elseif (($set_visibility == 'v') && ($num > 0)) {
            $sql = "UPDATE $tbl_tool SET
                        c_id = $course_id,
                        name = '$name',
                        link = '$link',
                        image = 'scormbuilder.gif',
                        visibility = '$v',
                        admin = '0',
                        address = 'pastillegris.gif',
                        added_tool = 0,
                        session_id = $session_id
            	    WHERE c_id = ".$course_id." AND (link='$link' and image='scormbuilder.gif' $session_condition)";
        } else {
            // Parameter and database incompatible, do nothing, exit.
            return false;
        }
        Database::query($sql);
    }
/**
 * Inserts a new element in a learnpath table (item or chapter)
 * @param		string	Element type ('chapter' or 'item')
 * @param		string	Chapter name
 * @param		string	Chapter description (optional)
 * @param		integer	Parent chapter ID (default: 0)
 * @param		integer Learnpath ID
 * @param		mixed		If type 'item', then array(prereq_id=>value, prereq_..)
 * @return	integer	The new chapter ID, or false on failure
 * @TODO	Finish this function before it is used. Currently only chapters can be added using it.
 * @note This function is currently never used!
 */
function insert_item($type = 'item', $name, $chapter_description = '', $parent_id = 0, $learnpath_id = 0, $params = null) {
    $tbl_learnpath_chapter	= Database :: get_course_table(TABLE_LEARNPATH_CHAPTER);
    $tbl_learnpath_item 	= Database :: get_course_table(TABLE_LEARNPATH_ITEM);

    $course_id = api_get_course_int_id();

    // Getting the last order number from the chapters table, in this learnpath, for the parent chapter given.
    $sql = "SELECT * FROM $tbl_learnpath_chapter
            WHERE c_id = $course_id AND lp_id=$learnpath_id  AND parent_item_id = $parent_id
            ORDER BY display_order DESC";
    $result = Database::query($sql);
    $row = Database::fetch_array($result);
    $last_chapter_order = $row['display_order'];

    // Getting the last order number of the items.
    $sql = "SELECT * FROM $tbl_learnpath_item
            WHERE c_id = $course_id AND parent_item_id = $parent_id
            ORDER BY display_order DESC";
    $result = Database::query($sql);
    $row = Database::fetch_array($result);
    $last_item_order = $row['display_order'];
    $new_order = max($last_chapter_order, $last_item_order) + 1;

    if ($type === 'chapter') {
        $sql = "INSERT INTO $tbl_learnpath_chapter (c_id, lp_id, chapter_name, chapter_description, display_order)
				VALUES ( $course_id,
						'".domesticate($learnpath_id)."',
                        '".domesticate(htmlspecialchars($name))."',
                        '".domesticate(htmlspecialchars($chapter_description))."',
                        $new_order )";
        $result = Database::query($sql);
        if ($result === false) {
            return false;
        }
        $id = Database :: insert_id();
    } elseif ($type === 'item') {
        $sql = "INSERT INTO $tbl_learnpath_item (c_id, parent_item_id, item_type, display_order) VALUES
        		($course_id, '".domesticate($parent_id)."','".domesticate(htmlspecialchars($type))."', $new_order )";
        $result = Database::query($sql);
        if ($result === false) {
            return false;
        }
        $id = Database :: insert_id();
    }
    return $id;
}