123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- <?php
- function create_cat_def($title="", $comment="", $nbline="5")
- {
- global $TBL_USERINFO_DEF;
- if ( 0 == (int) $nbline || empty($title))
- {
- return false;
- }
- $sql = "SELECT MAX(`rank`) maxRank FROM ".$TBL_USERINFO_DEF."";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if ($result) $maxRank = mysql_fetch_array($result);
- $maxRank = $maxRank['maxRank'];
- $thisRank = $maxRank + 1;
- $title = trim($title);
- $comment = trim($comment);
- $sql = "INSERT INTO ".$TBL_USERINFO_DEF." SET
- `title` = '$title',
- `comment` = '$comment',
- `line_count` = '$nbline',
- `rank` = '$thisRank'";
- api_sql_query($sql,__FILE__,__LINE__);
- return true;
- }
- function edit_cat_def($id, $title, $comment, $nbline)
- {
- global $TBL_USERINFO_DEF;
- if ( 0 == (int) $nbline || 0 == (int) $id )
- {
- return false;
- }
- $title = trim($title);
- $comment = trim($comment);
- $sql = "UPDATE ".$TBL_USERINFO_DEF." SET
- `title` = '$title',
- `comment` = '$comment',
- `line_count` = '$nbline'
- WHERE id = '$id'";
- api_sql_query($sql,__FILE__,__LINE__);
- return true;
- }
- function remove_cat_def($id, $force = false)
- {
- global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
- if ( (0 == (int) $id || $id == "ALL") || ! is_bool($force))
- {
- return false;
- }
- if ( $id != "ALL")
- {
- $sqlCondition = " WHERE id = '$id'";
- } else {
- $sqlCondition = "";
- }
- if ($force == false)
- {
- $sql = "SELECT * FROM ".$TBL_USERINFO_CONTENT." ".$sqlCondition;
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if ( mysql_num_rows($result) > 0)
- {
- return false;
- }
- }
- $sql = "DELETE FROM ".$TBL_USERINFO_DEF." ".$sqlCondition;
- api_sql_query($sql,__FILE__,__LINE__);
- }
- function move_cat_rank($id, $direction) // up & down.
- {
- global $TBL_USERINFO_DEF;
- if ( 0 == (int) $id || ! ($direction == "up" || $direction == "down") )
- {
- return false;
- }
- $sql = "SELECT rank FROM ".$TBL_USERINFO_DEF." WHERE id = '$id'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) < 1)
- {
- return false;
- }
- $cat = mysql_fetch_array($result);
- $rank = (int) $cat["rank"];
- return move_cat_rank_by_rank($rank, $direction);
- }
- function move_cat_rank_by_rank($rank, $direction) // up & down.
- {
- global $TBL_USERINFO_DEF;
- if ( 0 == (int) $rank || ! ($direction == "up" || $direction == "down") )
- {
- return false;
- }
- if ($direction == "down")
- {
- $sort = "ASC";
- $compOp = ">=";
- }
- else
- {
- $sort = "DESC";
- $compOp = "<=";
- }
-
- $sql = "SELECT id, rank FROM ".$TBL_USERINFO_DEF." WHERE rank $compOp $rank
- ORDER BY rank $sort LIMIT 2";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) < 2)
- {
- return false;
- }
- $thisCat = mysql_fetch_array($result);
- $nextCat = mysql_fetch_array($result);
- $sql1 = "UPDATE ".$TBL_USERINFO_DEF." SET rank ='".$nextCat['rank'].
- "' WHERE id = '".$thisCat['id']."'";
- $sql2 = "UPDATE ".$TBL_USERINFO_DEF." SET rank ='".$thisCat['rank'].
- "' WHERE id = '".$nextCat['id']."'";
- api_sql_query($sql1,__FILE__,__LINE__);
- api_sql_query($sql2,__FILE__,__LINE__);
- return true;
- }
- function update_user_course_properties($user_id, $course_code, $properties)
- {
- global $tbl_coursUser,$_user;
- $sqlChangeStatus = "";
- if ($user_id != $_user['user_id'])
- $sqlChangeStatus = "`status` = '".$properties['status']."',";
- $result = api_sql_query("UPDATE $tbl_coursUser
- SET `role` = '".$properties['role']."',
- ".$sqlChangeStatus."
- `tutor_id` = '".$properties['tutor']."'
- WHERE `user_id` = '".$user_id."'
- AND `course_code` = '".$course_code."'",__FILE__,__LINE__);
- if (mysql_affected_rows() > 0)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- function fill_new_cat_content($definition_id, $user_id, $content="", $user_ip="")
- {
- global $TBL_USERINFO_CONTENT;
- if (empty($user_ip))
- {
- global $REMOTE_ADDR;
- $user_ip = $REMOTE_ADDR;
- }
- $content = trim($content);
- if ( 0 == (int) $definition_id || 0 == (int) $user_id || $content == "")
- {
-
- return false;
- }
-
- $sql = "SELECT id FROM ".$TBL_USERINFO_CONTENT."
- WHERE `definition_id` = '$definition_id'
- AND `user_id` = '$user_id'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) > 0)
- {
- return false;
- }
- $sql = "INSERT INTO ".$TBL_USERINFO_CONTENT." SET
- `content` = '$content',
- `definition_id` = '$definition_id',
- `user_id` = '$user_id',
- `editor_ip` = '$user_ip',
- `edition_time` = now()";
- api_sql_query($sql,__FILE__,__LINE__);
- return true;
- }
- function edit_cat_content($definition_id, $user_id, $content ="", $user_ip="")
- {
- global $TBL_USERINFO_CONTENT;
- if (empty($user_ip))
- {
- global $REMOTE_ADDR;
- $user_ip = $REMOTE_ADDR;
- }
- if (0 == (int) $user_id || 0 == (int) $definition_id)
- {
- return false;
- }
- $content = trim($content);
- if ( trim($content) == "")
- {
- return cleanout_cat_content($user_id, $definition_id);
- }
- $sql= "UPDATE ".$TBL_USERINFO_CONTENT." SET
- `content` = '$content',
- `editor_ip` = '$user_ip',
- `edition_time` = now()
- WHERE definition_id = '$definition_id' AND user_id = '$user_id'";
- api_sql_query($sql,__FILE__,__LINE__);
- return true;
- }
- function cleanout_cat_content($user_id, $definition_id)
- {
- global $TBL_USERINFO_CONTENT;
- if (0 == (int) $user_id || 0 == (int) $definition_id)
- {
- return false;
- }
- $sql = "DELETE FROM ".$TBL_USERINFO_CONTENT."
- WHERE user_id = '$user_id' AND definition_id = '$definition_id'";
- api_sql_query($sql,__FILE__,__LINE__);
- return true;
- }
- function get_course_user_info($user_id)
- {
- global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
- $sql = "SELECT cat.id catId, cat.title,
- cat.comment , content.content
- FROM ".$TBL_USERINFO_DEF." cat LEFT JOIN ".$TBL_USERINFO_CONTENT." content
- ON cat.id = content.definition_id AND content.user_id = '$user_id'
- ORDER BY cat.rank, content.id";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) > 0)
- {
- while ($userInfo = mysql_fetch_array($result, MYSQL_ASSOC))
- {
- $userInfos[]=$userInfo;
- }
- return $userInfos;
- }
- return false;
- }
- function get_main_user_info($user_id, $courseCode)
- {
- if (0 == (int) $user_id)
- {
- return false;
- }
- $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $table_user = Database::get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT u.lastname lastName, u.firstname firstName,
- u.email, u.picture_uri picture, cu.role,
- cu.`status` `status`, cu.tutor_id
- FROM $table_user u, $table_course_user cu
- WHERE u.user_id = cu.user_id
- AND u.user_id = '$user_id'
- AND cu.course_code = '$courseCode'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) > 0)
- {
- $userInfo = mysql_fetch_array($result, MYSQL_ASSOC);
- return $userInfo;
- }
- return false;
- }
- function get_cat_content($userId, $catId)
- {
- global $TBL_USERINFO_CONTENT, $TBL_USERINFO_DEF;
- $sql = "SELECT cat.id catId, cat.title,
- cat.comment , cat.line_count,
- content.id contentId, content.content
- FROM ".$TBL_USERINFO_DEF." cat LEFT JOIN ".$TBL_USERINFO_CONTENT." content
- ON cat.id = content.definition_id
- AND content.user_id = '$userId'
- WHERE cat.id = '$catId' ";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) > 0)
- {
- $catContent = mysql_fetch_array($result, MYSQL_ASSOC);
- $catContent['nbline'] = $catContent['line_count'];
- return $catContent;
- }
- return false;
- }
- function get_cat_def($catId)
- {
- global $TBL_USERINFO_DEF;
- $sql = "SELECT id, title, comment, line_count, rank FROM ".$TBL_USERINFO_DEF." WHERE id = '$catId'";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) > 0)
- {
- $catDef = mysql_fetch_array($result, MYSQL_ASSOC);
- $catDef['nbline'] = $catDef['line_count'];
- return $catDef;
- }
- return false;
- }
- function get_cat_def_list()
- {
- global $TBL_USERINFO_DEF;
- $sql = "SELECT id catId, title, comment , line_count
- FROM ".$TBL_USERINFO_DEF."
- ORDER BY rank";
- $result = api_sql_query($sql,__FILE__,__LINE__);
- if (mysql_num_rows($result) > 0)
- {
- while ($cat_def = mysql_fetch_array($result, MYSQL_ASSOC))
- {
- $cat_def_list[]=$cat_def;
- }
- return $cat_def_list;
- }
- return false;
- }
- function htmlize($phrase)
- {
- return nl2br(htmlspecialchars($phrase));
- }
- function replace_dangerous_char($string)
- {
- $search[]="/" ; $replace[]="-";
- $search[]="\|"; $replace[]="-";
- $search[]="\""; $replace[]=" ";
- foreach($search as $key=>$char )
- {
- $string = str_replace($char, $replace[$key], $string);
- }
- return $string;
- }
|