2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Adaptive Technology Resource Centre / University of Toronto */
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 /****************************************************************/
15 require_once(AT_SOCIAL_INCLUDE.'classes/Activity.class.php');
16 require_once(AT_SOCIAL_INCLUDE.'classes/Application.class.php');
17 require_once(AT_SOCIAL_INCLUDE.'constants.inc.php');
20 * Object for Applications, (aka Gadgets)
25 function Applications(){}
28 * Retrieve a list of applications' titles
29 * @param boolean true if we only want to list the applications that we allow via the settings, false otherwise.
30 * @return hash of applications, id=>app obj
32 function listMyApplications($use_settings=false){
36 $sql = 'SELECT id, title FROM '.TABLE_PREFIX.'social_applications a, (SELECT application_id FROM '.TABLE_PREFIX.'social_members_applications WHERE member_id='.$_SESSION['member_id'].') AS apps WHERE a.id=apps.application_id';
37 $result = mysql_query($sql, $db);
38 $home_settings = $this->getHomeDisplaySettings();
40 while($row = mysql_fetch_assoc($result)){
41 $app = new Application($row['id']);
43 if(!isset($home_settings[$row['id']])){
47 $hash[$row['id']] = $app;
54 * Retrieve a list of all installed applications
56 function listApplications(){
60 $sql = 'SELECT * FROM '.TABLE_PREFIX.'social_applications';
61 $result = mysql_query($sql, $db);
63 while ($row = mysql_fetch_assoc($result)){
64 $hash[$row['id']] = new Application($row['id']);
72 * @param array array of application_id to be deleted.
74 function deleteApplications($ids){
76 $id_list = implode(', ', $ids);
77 $sql = 'DELETE FROM '.TABLE_PREFIX."social_applications WHERE id IN ($id_list)";
78 mysql_query($sql, $db);
82 * To determine which application to show on the home tab
83 * Save the settings in serialized format.
84 * @param mixed settings array. [note: upgrade this to an object if needed later on]
86 function setHomeDisplaySettings($settings){
87 global $db, $addslashes;
88 $settings = $addslashes(serialize($settings));
89 $sql = 'REPLACE INTO '.TABLE_PREFIX."social_user_settings SET app_settings='".$settings."', member_id=".$_SESSION['member_id'];
90 $result = mysql_query($sql, $db);
95 * Return the <a> link of an application by the given id.
96 * @param string the title/name of this application
97 * @param int application id
98 * @return THe <a> tag link of the requested application.
100 function getAppLink($title, $id){
101 return '<a href="'.url_rewrite(AT_SOCIAL_BASENAME.'applications.php?app_id='.$id) . '"><b>' . $title . '</b></a>';
106 * Get the home display setting
107 * @return array of settings that define which gadget to be displayed on the social home page.
109 function getHomeDisplaySettings(){
111 $sql = 'SELECT app_settings FROM '.TABLE_PREFIX.'social_user_settings WHERE member_id='.$_SESSION['member_id'];
112 $rs = mysql_query($sql, $db);
114 list($settings) = mysql_fetch_array($rs);
116 return unserialize($settings);