(First_name)? First_name.Last_name_initial : Anonymous * @param String $login login name string * @return String the full name of the member */ function get_member_name($login){ global $db; $query="SELECT last_name, first_name FROM ".TABLE_PREFIX."members WHERE login='{$login}'"; $result=mysql_query($query, $db); $count=mysql_affected_rows(); if ($count == 1) { //in this case, the login is instructor or student $result=mysql_fetch_array($result); if (empty($result['first_name'])){ $name=_AT('anonymous'); } else if (empty($result['last_name'])){ $name=$result['first_name']; } else { $temp=substr($result['last_name'], 0, 1); $name=$result['first_name'].'.'.$temp; } return $name; } else if ($count==0){ //found nobody, check if the user is administrator $query="SELECT login FROM ".TABLE_PREFIX."admins WHERE login='{$login}'"; $result=mysql_query($query, $db); $count=mysql_affected_rows(); if ($count==1){ //admin is detected return _AT('pa_tag_administrator'); } } } /** * @desc This pagination function returns an array which has the start and end information to be used * @param int $display_limit maximum number of images displayed in the page * @param int $page_limit maximum number of pages displayed in the page * @param int $course_id course id * @param int $current current page * @param int $last_page last_page number * @return Array array contains the start and end information for page table */ function get_page_array($display_limit, $page_limit, $current, $last_page){ $start=1; if ($last_page <= ($start+$page_limit-1)){ //initialize the end variable if the last page is less than start+display-1 $end=$last_page; } else { $end=$start+$page_limit-1; } $process=true; while ($process==true){ if (($current >= $start) && ($current <= $end)){ $array['start']=$start; $array['end']=$end; $process=false; } else { $start=$end+1; $end=$start+$page_limit-1; if ($end > $last_page){ $end=$last_page; } } } $array['last_page']=$last_page; $array['previous']=$current-1; $array['next']=$current+1; $array['current']=$current; return $array; } /** * @desc This function checks if the image exists in the database * @param int $image_id image id * @param int $course_id course id * @return boolean it returns true if the image exists in database. Otherwise, it returns false */ function image_exist($image_id, $course_id){ global $db; $table_name=get_table_name(IMAGE); $query="SELECT * FROM ".$table_name." WHERE course_id=".$course_id." AND image_id=".$image_id; $result=mysql_query($query, $db); $count=mysql_affected_rows(); if ($count == 1){ // there should be only 1 image return true; } else { return false; } } /** * @desc This function checks if the comment exists in the database * @param int $comment_id comment id * @param int $course_id course id * @return boolean returns true if the comment exists in database. Otherwise, it returns false */ function comment_exist($comment_id, $course_id){ global $db; $table_name=get_table_name(COMMENT); $query="SELECT * FROM ".$table_name." WHERE course_id=".$course_id." AND comment_id=".$comment_id; $result=mysql_query($query, $db); $count=mysql_affected_rows(); if ($count == 1){ //there should be only 1 comment return true; } else { return false; } } /** * @desc This function returns an array which has a list of the courses * @return Array array which contains title and course_id */ function get_course_list(){ global $db; $table=TABLE_PREFIX.'courses'; $query="SELECT course_id, title FROM ".$table." ORDER BY created_date"; $result=mysql_query($query, $db); $i=0; while($row=mysql_fetch_array($result)){ $array[$i]['title']=$row['title']; $array[$i]['id']=$row['course_id']; $i++; } return $array; } /** * @desc This function returns the course title * @param int $course_id course id * @return String course title */ function get_course_title($course_id){ global $db; $table=TABLE_PREFIX.'courses'; $query="SELECT title FROM ".$table." WHERE course_id=".$course_id; $result=mysql_query($query, $db); $result=mysql_fetch_array($result); return $result['title']; } /** * @desc This function checks if the course exists or not * @param int $course_id course id * @return Boolean true if exist */ function course_exist($id){ global $db; $table=TABLE_PREFIX.'courses'; $query="SELECT course_id FROM ".$table." WHERE course_id='{$id}'"; $result=mysql_query($query, $db); $count=mysql_affected_rows(); if ($count==1){ // It should affect only one record return true; } else { return false; } } /** * @desc This function checks whether the given input belongs to the user * @param int $choose IMAGE or COMMENT to choose * @param int $image_id image id * @param int $course_id course id * @param int $comment_id comment_id * @return Boolean true if the input belongs to the user */ function user_own($choose, $image_id, $course_id, $comment_id=NOT_SET){ global $db; $bool=false; $table=get_table_name($choose); switch ($choose){ case IMAGE: $query="SELECT login FROM ".$table." WHERE course_id=".$course_id." AND image_id=".$image_id; break; case COMMENT: $query="SELECT login FROM ".$table." WHERE course_id=".$course_id." AND image_id=".$image_id." AND comment_id=".$comment_id; break; } $result=mysql_query($query, $db); $result=mysql_fetch_array($result); $count=mysql_affected_rows(); if (is_admin_for_course()){ $bool=true; } else if ($count!=1) { //there should be only one owner global $msg; $msg->addError('pa_func_user_own'); redirect('index.php'); } else { if ($result['login']==$_SESSION['login']){ $bool=true; } } return $bool; } /** * @desc This function changes the image status * @param int $image_id image id * @param int $course_id course id * @param int $status image status, APPROVED, DISAPPROVED or POSTED_NEW */ function modify_image_status($image_id, $course_id, $status){ If (($status==APPROVED || $status==DISAPPROVED || $status==POSTED_NEW) && image_exist($image_id, $course_id)){ global $db; $table=get_table_name(IMAGE); $query="UPDATE ".$table." SET status=".$status." WHERE image_id=".$image_id." AND course_id=".$course_id; $result=mysql_query($query, $db); } } /** * @desc This function changes the comment status * @param int $comment_id comment id * @param int $course_id course id * @param int $status comment status, APPROVED, DISAPPROVED or POSTED_NEW */ function modify_comment_status($comment_id, $course_id, $status){ if (($status==APPROVED || $status==DISAPPROVED || $status==POSTED_NEW) && comment_exist($comment_id, $course_id)){ global $db; $table=get_table_name(COMMENT); $query="UPDATE ".$table." SET status=".$status." WHERE course_id=".$course_id." AND comment_id=".$comment_id; $result=mysql_query($query, $db); } } /** * @desc This function returns the moderation status for the course. If unmoderated, the course adds user submissions immediately * @param int $course_id course_id * @return int moderation status for the course, ENABLED or DISABLED */ function get_config_mode($course_id){ global $db; $table=get_table_name(CONFIG); $query="SELECT status FROM ".$table." WHERE course_id=".$course_id; $result=mysql_query($query, $db); $count=mysql_affected_rows(); if ($count==1){ //should be one configuration for the course $result=mysql_fetch_array($result); return $result['status']; } else { //configuration does not exist, so make one $query="INSERT INTO ".$table." SET course_id=".$course_id.", status=".CONFIG_DISABLED.", date=NOW()"; mysql_query($query, $db); return CONFIG_DISABLED; } } /** * @desc This function modifies the moderation status * @param int $course_id course id * @param int $status moderation status */ function modify_config_mode($course_id, $status){ global $db; $table=get_table_name(CONFIG); $query="UPDATE ".$table." SET status=".$status." WHERE course_id=".$course_id; mysql_query($query, $db); } /* * @desc This function returns the maximum file size for the course * @param int $course_id course id * @return int max_file_size */ function get_max_file_size($course_id){ global $db; $query="SELECT max_file_size FROM ".TABLE_PREFIX."courses WHERE course_id=".$course_id; $result=mysql_query($query, $db); $count=mysql_affected_rows(); if ($count==1){ $result=mysql_fetch_array($result); if ($result['max_file_size']>0){ return $result['max_file_size']; } else { return NOT_SET; } } else { return NOT_SET; } } ?>