+++ /dev/null
-<?php\r
-/*==============================================================\r
- Photo Album \r
- ==============================================================\r
- Copyright (c) 2006 by Dylan Cheon & Kelvin Wong \r
- Institute for Assistive Technology / University of Victoria \r
- http://www.canassist.ca/ \r
- \r
- This program is free software. You can redistribute it and/or\r
- modify it under the terms of the GNU General Public License \r
- as published by the Free Software Foundation. \r
- ==============================================================\r
- */\r
-// $Id:\r
-\r
-/**\r
- * @desc This file defines some general purpose functions used on almost every page\r
- * @author Dylan Cheon\r
- * @copyright 2006 Institute for Assistive Technology / University of Victoria\r
- * @link http://www.canassist.ca/ \r
- * @license GNU\r
- */\r
- \r
- \r
-/**\r
- * @desc The function prevents file name collision. It also converts spaces into underscores and renames files to jpeg extensions\r
- * @param String $location location string\r
- * @param String $image_name image name\r
- * @return String new image name\r
- */\r
-function modify_image_name($location, $image_name){\r
- $image_name=ereg_replace(" ", "_", $image_name);\r
- $temp_image=without_ext($image_name);\r
- $new_name=$temp_image.'.jpg';\r
- $temp=$new_name;\r
- $i=0;\r
- while (image_name_duplicate_check($location, $temp)!=true){\r
- $temp=insert_into_image_name($new_name, $i);\r
- $i++;\r
- }\r
- return $temp;\r
-}\r
-\r
-\r
-/**\r
- * @desc This helper function checks if there is an image with the same name in the folder \r
- * @param String $location location folder name\r
- * @param String $image name image file name\r
- * @return Boolean true if the image name is unique to the folder\r
- */ \r
-function image_name_duplicate_check($location, $image_name){\r
- $image_file=AT_CONTENT_DIR.$location.$image_name;\r
- if (is_file($image_file)){\r
- return false;\r
- } else {\r
- return true;\r
- }\r
-}\r
- \r
- \r
-/**\r
- * @desc This function inserts the given string into the image file name string. It is used to prevent file name collisions\r
- * @param String $image name image name string\r
- * @param String $insert insert string\r
- * @return String new image name\r
- */\r
-function insert_into_image_name($image_name, $insert){\r
- $position=strpos($image_name, '.');\r
- $string1=substr($image_name, 0, $position);\r
- $string2=substr($image_name, $position+1);\r
- $result=$string1.'_'.$insert.'.'.$string2;\r
- return $result;\r
-}\r
- \r
-/**\r
- * @desc This function checks whether the user is an instructor or administrator. If the user is neither student nor guest, it returns true\r
- * @return Boolean true if the user is either administrator or instructor\r
- */\r
-function is_admin_for_course(){\r
- if ($_SESSION['privileges'] != NORMAL_USER){ \r
- return true;\r
- } else if ($_SESSION['is_admin']==true){\r
- return true;\r
- } else {\r
- return false;\r
- }\r
-}\r
- \r
-/**\r
- * @desc This function copies the image file to given location\r
- * @param String $image filename to be named\r
- * @param String $temp_image_file image source to be copied\r
- * @param String $location location folder name\r
- */ \r
-function image_to_this_location($image, $temp_image_file, $location){\r
- $store_folder=AT_CONTENT_DIR.$location;\r
- $store_image=$store_folder.$image;\r
- \r
- if (!@copy($temp_image_file, $store_image)){\r
- global $msg;\r
- $msg->addError('pa_func_copy');\r
- redirect('index.php');\r
- } \r
- @chmod($store_image, 0777);\r
-}\r
- \r
- \r
-/**\r
- * @desc This function deletes the files of the given Array (array should be mysql resource)\r
- * @param Array $array array which contains the file names and locations\r
- */\r
-function delete_image_files($array){\r
- error_reporting(E_ALL ^ E_WARNING ^ E_NOTICE);\r
- while ($row=mysql_fetch_array($array)){ \r
- $location=AT_CONTENT_DIR.$row['location'];\r
- $image_path=$location.$row['view_image_name'];\r
- $thumb_path=$location.$row['thumb_image_name'];\r
- unlink($image_path);\r
- unlink($thumb_path);\r
- }\r
-}\r
- \r
- \r
-/**\r
- * @desc This function convert the newline character to <br>\r
- * @param String $string string to be converted\r
- * @return String the new string\r
- */\r
-function convert_newlines($string){\r
- $input=eregi_replace("\n", "<br/>", $string);\r
- return $input;\r
-} \r
- \r
- \r
-/**\r
- * @desc This function redirect the user to the requested address\r
- * @param String $addr redirection destination URI\r
- */\r
-function redirect($addr){\r
- $url=ATUTOR_PREFIX.BASE_PATH.$addr;\r
- echo ("\r
- <META http-equiv='refresh' content='0;URL=$url'>\r
- "); \r
- exit; \r
-}\r
- \r
- \r
- \r
-/**\r
- * @desc This function returns the positive int value of the given input. If the given input is not numeric, it returns 1\r
- * @param int $input input value\r
- * @return int positive int value\r
- */\r
-function to_pos_int($input){\r
- $result;\r
- if (is_numeric($input)){\r
- $temp=intval($input);\r
- $result=max(1, $temp);\r
- } else {\r
- $result=1;\r
- }\r
- return $result;\r
-} \r
- \r
-/**\r
- * @desc This function returns the file name without an extention\r
- * @param String $input file name \r
- * @return String file name without extention\r
- */\r
-function without_ext($input){\r
- $pos=strpos($input, ".");\r
- $string=substr($input, 0, $pos);\r
- if (empty($string)){\r
- return "unknown_image";\r
- } else {\r
- return $string;\r
- }\r
-}\r
-\r
-/**\r
- * @desc This function creates a folder.\r
- * @param String $folder folder name\r
- */ \r
-function create_folder($folder){\r
- $folder=AT_CONTENT_DIR.$folder;\r
- if (!is_dir($folder)){\r
- if (!mkdir($folder)){\r
- global $msg;\r
- $msg->addError('pa_func_mkdir');\r
- redirect('index.php');\r
- }\r
- \r
- }\r
-}\r
-\r
-/**\r
- * @desc This function makes a temp folder under the users folder\r
- * @return String temp folder path\r
- */\r
-function make_temp_folder(){\r
- $my_dir=ALBUM_IMAGE_STORE.$_SESSION['login'].'/';\r
- create_folder($my_dir);\r
- if(!is_writable($my_dir) && @chmod($my_dir, 0777)){\r
- $msg->addError('pa_func_make_temp_folder');\r
- redirect('index.php');\r
- }\r
- $temp_folder=$my_dir.TEMP_FOLDER_NAME;\r
- create_folder($temp_folder);\r
- if(!is_writable($temp_folder) && @chmod($temp_folder, 0777)){\r
- $msg->addError('pa_func_make_temp_folder');\r
- redirect('index.php');\r
- }\r
- return $temp_folder;\r
-}\r
-\r
-\r
-/**\r
- * @desc This function deletes all the files in the temp folder directory\r
- */\r
-function clear_temp_folder(){\r
- global $msg;\r
- $temp_dir=AT_CONTENT_DIR.ALBUM_IMAGE_STORE.$_SESSION['login'].'/temp/';\r
- if (is_dir($temp_dir)){ \r
- $temp=substr($temp_dir, 0, -1);\r
- if (!$files=@opendir($temp)){\r
- $msg->addError('pa_func_clear_temp_folder_open');\r
- redirect('../../index.php');\r
- }\r
- while ($obj=readdir($files)){\r
- if ($obj == '.' || $obj=='..' || $obj=='.svn'){\r
- continue;\r
- } else {\r
- if (!@unlink($temp_dir.$obj)){\r
- $msg->addError('pa_func_clear_temp_folder_unlink');\r
- redirect('../../index.php');\r
- }\r
- }\r
- }\r
- }\r
-}\r
-\r
-\r
-/**\r
- * @desc This function redirects to the appropriate page when an error occurs depending on the user type\r
- */\r
-function out(){\r
- if ($_SESSION['pa']['choose']==IMAGE){\r
- if ($_SESSION['pa']['mode']=='edit'){\r
- if ($_SESSION['pa']['my_pic_mode']==true){\r
- redirect('my_photo.php');\r
- } else if ((!is_admin_for_course()) && (get_config_mode($_SESSION['pa']['course_id'])==CONFIG_ENABLED)){\r
- redirect('index.php');\r
- } else {\r
- redirect('view.php?image_id='.$_SESSION['pa']['image_id']);\r
- }\r
- } else if ($_SESSION['pa']['mode']=='add'){\r
- if ($_SESSION['pa']['instructor_mode']==true){\r
- redirect('instructor_image.php');\r
- } else if ($_SESSION['pa']['administrator_mode']==true){\r
- redirect('admin_image_list.php');\r
- } else {\r
- redirect('index.php');\r
- }\r
- } else { //mode is delete\r
- if ($_SESSION['pa']['instructor_mode']==true){\r
- redirect('instructor_image.php');\r
- } else if ($_SESSION['pa']['administrator_mode']==true){\r
- redirect('admin_image_list.php');\r
- } else {\r
- redirect('index.php');\r
- }\r
- }\r
- } else { //choose is comment\r
- redirect('view.php?image_id='.$_SESSION['pa']['image_id']);\r
- }\r
-}\r
-\r
- \r
-?>\r