2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Inclusive Design Institute */
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){
77 //foreach of these ids, delete all their associations
78 foreach ($ids as $id){
79 $app = new Application($id);
80 $app->deleteApplication();
83 //now delete it from the application table
84 $id_list = implode(', ', $ids);
85 $sql = 'DELETE FROM '.TABLE_PREFIX."social_applications WHERE id IN ($id_list)";
86 mysql_query($sql, $db);
90 * To determine which application to show on the home tab
91 * Save the settings in serialized format.
92 * @param mixed settings array. [note: upgrade this to an object if needed later on]
94 function setHomeDisplaySettings($settings){
95 global $db, $addslashes;
96 $settings = $addslashes(serialize($settings));
97 $sql = 'REPLACE INTO '.TABLE_PREFIX."social_user_settings SET app_settings='".$settings."', member_id=".$_SESSION['member_id'];
98 $result = mysql_query($sql, $db);
103 * Return the <a> link of an application by the given id.
104 * @param string the title/name of this application
105 * @param int application id
106 * @return THe <a> tag link of the requested application.
108 function getAppLink($title, $id){
109 return '<a href="'.url_rewrite(AT_SOCIAL_BASENAME.'applications.php?app_id='.$id) . '"><b>' . $title . '</b></a>';
114 * Get the home display setting
115 * @return array of settings that define which gadget to be displayed on the social home page.
117 function getHomeDisplaySettings(){
119 $sql = 'SELECT app_settings FROM '.TABLE_PREFIX.'social_user_settings WHERE member_id='.$_SESSION['member_id'];
120 $rs = mysql_query($sql, $db);
122 list($settings) = mysql_fetch_array($rs);
124 return unserialize($settings);