1392c3813859b6a05bd2bfeee8a05a46705afde5
[atutor.git] / mods / photos / module_install.php
1 <?php
2 /***********************************************************************/
3 /* ATutor                                                                                                                          */
4 /***********************************************************************/
5 /* Copyright (c) 2002-2009                                                                                         */
6 /* Adaptive Technology Resource Centre / Inclusive Design Institution  */
7 /* http://atutor.ca                                                                                                        */
8 /*                                                                                                                                         */
9 /* This program is free software. You can redistribute it and/or           */
10 /* modify it under the terms of the GNU General Public License             */
11 /* as published by the Free Software Foundation.                                           */
12 /***********************************************************************/
13 // $Id$
14
15 /*******
16  * the line below safe-guards this file from being accessed directly from
17  * a web browser. It will only execute if required from within an ATutor script,
18  * in our case the Module::install() method.
19  */
20 if (!defined('AT_INCLUDE_PATH')) { exit; }
21
22 /*******
23  * Note: the many options for these variables are used to decrease confusion.
24  *       TRUE | FALSE | 1 will be the convention.
25  *
26  * $_course_privilege
27  *     specifies the type of instructor privilege this module uses.
28  *     set to empty | FALSE | 0   to disable any privileges.
29  *     set to 1 | AT_PRIV_ADMIN   to use the instructor only privilege.
30  *     set to TRUE | 'new'        to create a privilege specifically for this module:
31  *                                will make this module available as a student privilege.
32  *
33  * $_admin_privilege
34  *    specifies the type of ATutor administrator privilege this module uses.
35  *    set to FALSE | AT_ADMIN_PRIV_ADMIN   to use the super administrator only privilege.
36  *    set to TRUE | 'new'                  to create a privilege specifically for this module:
37  *                                         will make this module available as an administrator privilege.
38  *
39  *
40  * $_cron_interval
41  *    if non-zero specifies in minutes how often the module's cron job should be run.
42  *    set to 0 or not set to disable.
43  */
44 $_course_privilege = TRUE; // possible values: FALSE | AT_PRIV_ADMIN | TRUE
45
46
47 /********
48  * the following code is used for creating a module-specific directory.
49  * it generates appropriate error messages to aid in its creation.
50  */
51 $directory = AT_PA_CONTENT_DIR;
52
53 /**
54  * check if GD is installed and is version 2 or higher
55  */
56 if (! extension_loaded('gd')) {
57         $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>'));
58 } else {
59         if (function_exists('gd_info')) {
60                 // use gd_info if possible...
61                 $gd_info = gd_info();
62                 preg_match('/\d/', $gd_info['GD Version'], $match);
63                 if ($match[0] < 2) {
64                         $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>'));
65                 } 
66                 //check GD support 
67                 $supported_images = array();
68                 if ($gd_info['GIF Create Support']) {
69                         $supported_images[] = 'gif';
70                 }
71                 if ($gd_info['JPG Support']) {
72                         $supported_images[] = 'jpg';
73                 }
74                 if ($gd_info['PNG Support']) {
75                         $supported_images[] = 'png';
76                 }
77                 if (!$supported_images) {
78                         $msg->addError(array('MODULE_INSTALL', '<li>This module must be able to support gif/jpg/png.  Please recompile your GD library with those types supported.</li>'));
79                 }
80         } else {
81                 // ...otherwise use phpinfo().
82                 ob_start();
83                 phpinfo(8);
84                 $info = ob_get_contents();
85                 ob_end_clean();
86                 $info = stristr($info, 'gd version');
87                 preg_match('/\d/', $info, $match);
88                 if ($match[0] < 2) {
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>'));
90            }
91         }
92 }
93
94 // check if the directory is writeable
95 if (!is_dir($directory) && !@mkdir($directory)) {
96         $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' does not exist. Please create it.</li>'));
97 } else if (!is_writable($directory) && @chmod($directory, 0666)) {
98         $msg->addError(array('MODULE_INSTALL', '<li>'.$directory.' is not writeable. On Unix issue the command <kbd>chmod a+rw</kbd>.</li>'));
99 }
100
101 /******
102  * the following code checks if there are any errors (generated previously)
103  * then uses the SqlUtility to run any database queries it needs, ie. to create
104  * its own tables.
105  */
106 if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) {
107         // deal with the SQL file:
108         require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php');
109         $sqlUtility =& new SqlUtility();
110
111         /*
112          * the SQL file could be stored anywhere, and named anything, "module.sql" is simply
113          * a convention we're using.
114          */
115         $sqlUtility->queryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX);
116 }
117 ?>