changed git call from https to git readonly
[atutor.git] / mods / photo_album / module_install.php
1 <?php\r
2 /*==============================================================\r
3   Photo Album\r
4  ==============================================================\r
5   Copyright (c) 2006 by Dylan Cheon & Kelvin Wong\r
6   Institute for Assistive Technology / University of Victoria\r
7   http://www.canassist.ca/                                    \r
8                                                                \r
9   This program is free software. You can redistribute it and/or\r
10   modify it under the terms of the GNU General Public License  \r
11   as published by the Free Software Foundation.                \r
12  ==============================================================\r
13  */\r
14 // $Id:\r
15 \r
16 /**\r
17  * @desc        This file installs the photo album module\r
18  * @author      Dylan Cheon & Kelvin Wong\r
19  * @copyright   2006, Institute for Assistive Technology / University of Victoria \r
20  * @link        http://www.canassist.ca/                                    \r
21  * @license GNU\r
22  */\r
23  \r
24 /**\r
25  * @desc the line below safe-guards this file from being accessed directly from a web browser. It will only execute if required from within an ATutor script, in our case the Module::install() method.\r
26  */\r
27 if (!defined('AT_INCLUDE_PATH')) { exit; }\r
28 if (!defined('AT_MODULE_PATH')) { exit; }\r
29 //define('AT_MODULE_PATH', realpath(AT_INCLUDE_PATH.'../mods') . DIRECTORY_SEPARATOR);\r
30 \r
31 /**\r
32  * Note: the many options for these variables are used to decrease confusion.\r
33  *       TRUE | FALSE | 1 will be the convention.\r
34  *\r
35  * $_course_privilege\r
36  *     specifies the type of instructor privilege this module uses.\r
37  *     set to empty | FALSE | 0   to disable any privileges.\r
38  *     set to 1 | AT_PRIV_ADMIN   to use the instructor only privilege.\r
39  *     set to TRUE | 'new'        to create a privilege specifically for this module:\r
40  *                                will make this module available as a student privilege.\r
41  *\r
42  * $_admin_privilege\r
43  *    specifies the type of ATutor administrator privilege this module uses.\r
44  *    set to FALSE | AT_ADMIN_PRIV_ADMIN   to use the super administrator only privilege.\r
45  *    set to TRUE | 'new'                  to create a privilege specifically for this module:\r
46  *                                         will make this module available as an administrator privilege.\r
47  */\r
48 $_course_privilege = TRUE; // possible values: FALSE | AT_PRIV_ADMIN | TRUE\r
49 $_admin_privilege  = TRUE; // possible values: FALSE | TRUE\r
50 \r
51 \r
52 /**\r
53  * the following code is used for creating a module-specific directory.\r
54  * it generates appropriate error messages to aid in its creation.\r
55  */\r
56 $pa_array[0]=AT_CONTENT_DIR.'photo_album';\r
57 \r
58 // check if the directory is writeable\r
59 foreach ($pa_array as $directory){\r
60         if (!is_dir($directory) && !@mkdir($directory)) {\r
61                 $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' does not exist. Please create it.</li>'));\r
62         } else if (!is_writable($directory) && @chmod($directory, 0777)) {\r
63                 $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' is not writeable. On Unix issue the command <kbd>chmod a+rw</kbd>.</li>'));\r
64         }\r
65 }\r
66 \r
67 /**\r
68  * check if GD is installed and is version 2 or higher\r
69  */\r
70 if (! extension_loaded('gd')) {\r
71         $msg->addError(array('MODULE_INSTALL', '<li>This module requires the GD Library. Please <a href="http://www.boutell.com/gd/" title="Link to GD web site">install it</a>.</li>'));\r
72 } else {\r
73         if (function_exists('gd_info')) {\r
74                 // use gd_info if possible...\r
75                 $gd_ver_info = gd_info();\r
76                 preg_match('/\d/', $gd_ver_info['GD Version'], $match);\r
77                 if ($match[0] < 2) {\r
78                         $msg->addError(array('MODULE_INSTALL', '<li>This module requires GD version 2 or higher. Please <a href="http://www.boutell.com/gd/" title="Link to GD web site">install it</a>.</li>'));\r
79                 }\r
80         } else {\r
81                 // ...otherwise use phpinfo().\r
82                 ob_start();\r
83                 phpinfo(8);\r
84                 $info = ob_get_contents();\r
85                 ob_end_clean();\r
86                 $info = stristr($info, 'gd version');\r
87                 preg_match('/\d/', $info, $match);\r
88                 if ($match[0] < 2) {\r
89                         $msg->addError(array('MODULE_INSTALL', '<li>This module requires the GD Library version 2 or higher. Please <a href="http://www.boutell.com/gd/" title="Link to GD web site">install it</a>.</li>'));\r
90            }\r
91         }\r
92 }\r
93 \r
94 /**\r
95  * the following code checks if there are any errors (generated previously)\r
96  * then uses the SqlUtility to run any database queries it needs, ie. to create\r
97  * its own tables.\r
98  */\r
99 if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) {\r
100         // deal with the SQL file:\r
101         require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php');\r
102         $sqlUtility =& new SqlUtility();\r
103 \r
104         /**\r
105          * the SQL file could be stored anywhere, and named anything, "module.sql" is simply\r
106          * a convention we're using.\r
107          */\r
108         $sqlUtility->queryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX);\r
109 }\r
110 \r
111 ?>\r