53eb8c7edbae3fb89469d73afcd7a7a83714dc6a
[atutor.git] / mods / social / applications.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2009                                                                              */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
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 $_user_location = 'public';
15
16 define('AT_INCLUDE_PATH', '../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 include(AT_SOCIAL_INCLUDE.'friends.inc.php');
19 include(AT_SOCIAL_INCLUDE.'classes/Application.class.php');
20 $_custom_css = $_base_path . AT_SOCIAL_BASENAME . 'module.css'; // use a custom stylesheet
21
22 if (!$_SESSION['valid_user']) {
23         require(AT_INCLUDE_PATH.'header.inc.php');
24         $info = array('INVALID_USER', $_SESSION['course_id']);
25         $msg->printInfos($info);
26         require(AT_INCLUDE_PATH.'footer.inc.php');
27         exit;
28 }
29
30 //initialization
31 $app = new Application();
32
33 // Install gadgets
34 if (isset($_POST['add_application']) && isset($_POST['app_url'])){
35         //check if curl is installed
36         if (!extension_loaded('curl')){
37                 $msg->addError('CURL_NOT_INSTALLED');
38                 header('Location: '. url_rewrite(AT_SOCIAL_BASENAME.'applications.php', AT_PRETTY_URL_IS_HEADER));
39                 exit; 
40         }
41         $app_url = $addslashes(trim($_POST['app_url']));
42         $gadget = $app->parseModulePrefs($app_url);
43         $gadget = $gadget[0];
44
45         if (empty($gadget->errors)){
46                 //add applicatoin to database
47                 $app->addApplication($gadget);
48                 $msg->addFeedback('GADGET_ADDED_SUCCESSFULLY');
49                 header('Location: '. url_rewrite(AT_SOCIAL_BASENAME.'applications.php', AT_PRETTY_URL_IS_HEADER));
50                 exit;
51         } else {
52                 $msg->addError(array('GADGET_ADDED_FAILURE', implode(', ', $gadget->errors)));
53                 header('Location: '. url_rewrite(AT_SOCIAL_BASENAME.'applications.php', AT_PRETTY_URL_IS_HEADER));
54                 exit; 
55         }
56 }
57
58 // Show all gadgets
59 if (isset($_POST['show_applications'])){
60         $list_of_all_apps = $app->listApplications();
61 }
62
63 //Display individual application
64 if (isset($_REQUEST['app_id'])){
65         $_REQUEST['app_id'] = intval($_REQUEST['app_id']);
66         $app = new Application($_REQUEST['app_id']);    //testing application 1, 2
67         
68         //Add application
69         if (isset($_GET['add']) && intval($_GET['add'])==1){
70                 $app->addMemberApplication($_SESSION['member_id'], $_GET['app_id']);
71                 $msg->addFeedback('GADGET_ADDED_SUCCESSFULLY');
72                 header('Location: '. url_rewrite(AT_SOCIAL_BASENAME.'applications.php', AT_PRETTY_URL_IS_HEADER));
73                 exit;
74         }
75
76         //Delete application
77         if (isset($_GET['delete']) && intval($_GET['delete']) > 0) {
78                 $app->deleteApplication();
79                 $msg->addFeedback('GADGET_REMOVED_SUCCESSFULLY');
80                 header('Location: '. url_rewrite(AT_SOCIAL_BASENAME.'applications.php', AT_PRETTY_URL_IS_HEADER));
81                 exit;
82         }
83
84         //Display application settings
85         if (isset($_GET['settings'])){
86                 include(AT_INCLUDE_PATH.'header.inc.php');
87                 $savant->assign('settings', $app->getSettings());       //userPrefs
88                 $savant->assign('user_settings', $app->getApplicationSettings($_SESSION['member_id']));
89                 $savant->assign('app_id', $app->getId());       //id
90                 $savant->display('application_settings.tmpl.php');
91                 include(AT_INCLUDE_PATH.'footer.inc.php');              
92                 exit;
93         }
94
95         //Save settings
96         if (isset($_POST['app_settings'])){
97                 foreach ($app->getSettings() as $key=>$value){
98                         if(isset($_POST[$key])){
99                                 //save values iff it is in the userPrefs serialized string.
100                                 //don't save values blindly from the $_POST.
101                                 $value = $addslashes($_POST[$key]);
102                                 $app->setApplicationSettings($_SESSION['member_id'], $key, $value);
103                         }
104                 }
105                 $msg->addFeedback('GADGET_SETTINGS_SAVED');
106                 header('Location: '. url_rewrite(AT_SOCIAL_BASENAME.'applications.php', AT_PRETTY_URL_IS_HEADER));
107                 exit;
108         }
109
110         //loop through all app and print out the thumbnail
111         $iframe_url = $app->getIframeUrl($_REQUEST['id'], 'canvas', $_GET['appParams']);
112
113         //display
114         include(AT_INCLUDE_PATH.'header.inc.php');
115         $savant->assign('iframe_url', $iframe_url);
116         $savant->assign('app', $app);
117         $savant->display('individual_application.tmpl.php');
118         include(AT_INCLUDE_PATH.'footer.inc.php');
119         exit;
120 }
121
122 //list all my applications
123 $list_of_my_apps = $app->listMyApplications();
124
125 include(AT_INCLUDE_PATH.'header.inc.php');
126 $savant->display('pubmenu.tmpl.php');
127 $savant->assign('list_of_my_apps', $list_of_my_apps);
128 $savant->assign('list_of_all_apps', $list_of_all_apps);
129 $savant->display('applications.tmpl.php');
130 include(AT_INCLUDE_PATH.'footer.inc.php');
131 ?>