d11b88aa241206d16a28c085f63786fdb3cb7e2c
[atutor.git] / mods / announcement_subscription / module_install.php
1 <?php\r
2 /*******\r
3  * the line below safe-guards this file from being accessed directly from\r
4  * a web browser. It will only execute if required from within an ATutor script,\r
5  * in our case the Module::install() method.\r
6  */\r
7 if (!defined('AT_INCLUDE_PATH')) { exit; }\r
8 require(AT_INCLUDE_PATH.'lib/constants.inc.php');\r
9 \r
10 $_course_privilege = TRUE; // possible values: FALSE | AT_PRIV_ADMIN | TRUE\r
11 $_admin_privilege  = TRUE; // possible values: FALSE | TRUE\r
12 $_cron_interval    = 0; // disable\r
13 \r
14 \r
15 /******\r
16  * the following code checks if there are any errors (generated previously)\r
17  * then uses the SqlUtility to run any database queries it needs, ie. to create\r
18  * its own tables.\r
19  */\r
20  \r
21 if (!$msg->containsErrors() && file_exists(dirname(__FILE__) . '/module.sql')) {\r
22         // deal with the SQL file:\r
23         require(AT_INCLUDE_PATH . 'classes/sqlutility.class.php');\r
24         $sqlUtility =& new SqlUtility();\r
25 \r
26         /*\r
27          * the SQL file could be stored anywhere, and named anything, "module.sql" is simply\r
28          * a convention we're using.\r
29          */\r
30         $sqlUtility->queryFromFile(dirname(__FILE__) . '/module.sql', TABLE_PREFIX);\r
31 }\r
32 \r
33 /******\r
34  * The following core files are changed: \r
35  * \r
36  *  editor/add_news.php:   \r
37  *\r
38  */  \r
39 \r
40 /******\r
41  * Open editor/add_news.php, check if changes need to be made, make them if neccessary\r
42  */ \r
43 \r
44 $installed=FALSE;\r
45 $needle = "if (!\$msg->containsErrors() && (!isset(\$_POST['setvisual']) || isset(\$_POST['submit']))) {";\r
46 $changes = "\n\t/***** \r
47 \t* Added by announcement_subscription: Send mail to announcement subscribers \r
48 \t*/\n\r
49 \t \$subscriberMod =& \$moduleFactory->getModule('announcement_subscription'); \r
50 \t if (\$subscriberMod->isEnabled() && !\$subscriberMod->isMissing()) { \r
51 \t\t include_once(AT_MODULE_PATH . 'announcement_subscription/sendmail.php'); \r
52 \t } \n\r
53 \t/***** \r
54 \t* End announcement_subscription \r
55 \t*/ \n ";\r
56 \r
57 \r
58 $filename=('../../editor/add_news.php');\r
59 if(!is_writable($filename)){\r
60 $msg->addError('ANOUNCEMENTSUB_INSTALL_UNWRITE');\r
61 }else{\r
62   $data = file($filename);\r
63   foreach($data as $line){\r
64     $newfile .= (strpos($line,$needle))? $line . "\n" . $changes . "\n": $line;\r
65     if(strpos($line,'announcement_subscription/sendmail.php')){\r
66       $msg->addInfo('ANNOUNCEMENTSUB_ALREADYINSTALLED_ADDNEWS');\r
67       $installed=TRUE;\r
68     }\r
69   }\r
70   \r
71   if (!$installed) {\r
72     $file = fopen('$filename','w');\r
73     if(fwrite($file,$newfile)){\r
74       $msg->addFeedback('ANNOUNCEMENTSUB_INSTALL_ADDNEWS');\r
75     }else{\r
76       $msg->addError('ANNOUNCEMENTSUB_INSTALL_ADDNEWS');\r
77     }\r
78     fclose($file);\r
79   }\r
80 }\r
81 \r
82 ?>\r