| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: buddylist_ui.module,v 1.6.2.2 2008/07/25 16:49:43 nodestroy Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 8 |
* contains core buddylist_ui functions to generate social networks |
* contains core buddylist_ui functions to generate social networks |
| 9 |
*/ |
*/ |
| 10 |
|
|
| 11 |
|
// inlude file with admin function |
| 12 |
|
include_once 'buddylist_ui.admin.inc'; |
| 13 |
|
|
| 14 |
/** |
/** |
| 15 |
* HOOKS |
* HOOKS |
| 16 |
*/ |
*/ |
| 80 |
} |
} |
| 81 |
|
|
| 82 |
/** |
/** |
| 83 |
|
* Implementation of hook_enable(). |
| 84 |
|
*/ |
| 85 |
|
function buddylist_ui_enable() { |
| 86 |
|
$rtypes = buddylist_ui_get_default_rtypes(); |
| 87 |
|
foreach($rtypes as $rtype) |
| 88 |
|
buddylist_api_rtype_save($rtype); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
|
/** |
| 92 |
|
* Implementation of hook_disable(). |
| 93 |
|
*/ |
| 94 |
|
function buddylist_ui_disable() { |
| 95 |
|
$rtypes = buddylist_ui_get_default_rtypes(); |
| 96 |
|
foreach($rtypes as $rtype) |
| 97 |
|
buddylist_api_rtype_delete($rtype); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
|
|
| 101 |
|
/** |
| 102 |
* FUNCTIONS |
* FUNCTIONS |
| 103 |
*/ |
*/ |
| 104 |
|
|
| 105 |
/** |
/** |
| 106 |
* Generates overview of relationtypes |
* Returns default relationtypes |
| 107 |
*/ |
*/ |
| 108 |
function buddylist_ui_admin_overview() { |
function buddylist_ui_get_default_rtypes() { |
| 109 |
$form = array(); |
return array( |
| 110 |
|
'buddy' => array( |
| 111 |
//active relationtypes |
'name' => 'buddy', |
| 112 |
$form['active'] = array('#value' => '<h2>'. t('Active relationtypes'). '</h2>'); |
'oneway' => 1, |
| 113 |
$form['active_table'] = buddylist_ui_admin_get_rtypes(1); |
), |
| 114 |
|
'fan' => array( |
| 115 |
//inactive relationtypes |
'name' => 'fan', |
| 116 |
$form['inactive'] = array('#value' => '<h2>'. t('Inactive relationtypes'). '</h2>'); |
'oneway' => 0, |
| 117 |
$form['inactive_table'] = buddylist_ui_admin_get_rtypes(0); |
) |
| 118 |
|
); |
|
return $form; |
|
| 119 |
} |
} |
| 120 |
|
|
| 121 |
/** |
/** |
| 132 |
} |
} |
| 133 |
|
|
| 134 |
/** |
/** |
| 135 |
* Generates table with active/inactive relationtypes and operation links |
* THEME |
| 136 |
*/ |
*/ |
|
function buddylist_ui_admin_get_rtypes($active_state) { |
|
|
// load all types |
|
|
$rtypes = buddylist_api_rtypes_load(); |
|
|
$final_types = array(); |
|
|
|
|
|
foreach($rtypes as $rtype) { |
|
|
// only add to table if the state matches |
|
|
if ($rtype->active == $active_state) { |
|
|
$path = 'admin/buddylist/rtypes/'. $rtype->rtid; |
|
|
$id = $rtype->rtid; |
|
|
$final_types[$id] = (array)$rtype; |
|
|
$ops = array(); |
|
|
$ops[] = l(t('edit'), $path .'/edit'); |
|
|
|
|
|
// only type 1 relationtypes can be deleted |
|
|
if($rtype->type == 1) |
|
|
$ops[] = l(t('delete'), $path .'/delete'); |
|
|
|
|
|
$final_types[$id]['oneway'] = ($final_types[$id]['oneway'] == 1) ? t('Yes') : t('No'); |
|
|
$final_types[$id]['type'] = ($final_types[$id]['type'] == 1) ? t('User') : t('Module'); |
|
|
|
|
|
unset($final_types[$id]['active']); |
|
|
|
|
|
$final_types[$id][] = implode(' ', $ops); |
|
|
} |
|
|
} |
|
|
|
|
|
// no relationtypes found |
|
|
if (!count($final_types)) { |
|
|
return array('#value' => '<p>'. t('None') .'</p>'); |
|
|
} |
|
|
|
|
|
$header = array(t('Relation ID'), t('Name'), t('Oneway'), t('Type'), t('Operations')); |
|
|
return array('#value' => theme('table', $header, $final_types)); |
|
|
} |
|
| 137 |
|
|
| 138 |
/** |
function buddylist_ui_theme() { |
| 139 |
* Returns the form for editing/adding a rtype |
return array( |
| 140 |
*/ |
|
|
function buddylist_ui_admin_form_edit(&$form_state, $rtid = NULL) { |
|
|
$form = array(); |
|
|
|
|
|
// only write rtid in form if we are in edit process |
|
|
if($rtid != NULL) { |
|
|
$form['rtid'] = array( |
|
|
'#type' => 'hidden', |
|
|
'#default_value' => $rtid->rtid, |
|
|
); |
|
|
} |
|
|
$form['name'] = array( |
|
|
'#type' => 'textfield', |
|
|
'#title' => t('Name'), |
|
|
'#maxlength' => 255, |
|
|
'#default_value' => $rtid->name, |
|
|
'#description' => t("Example: buddy, friend, colleague."), |
|
|
'#required' => TRUE, |
|
|
); |
|
|
$form['oneway'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('This is a oneway relationship'), |
|
|
'#default_value' => $rtid->oneway, |
|
|
'#description' => t('Check this if this relationship should only go one way (Example: Fan, Subscriber)'), |
|
|
); |
|
|
$form['active'] = array( |
|
|
'#type' => 'checkbox', |
|
|
'#title' => t('Relationtype is active'), |
|
|
'#default_value' => $rtid->active, |
|
|
'#description' => t('If checked, users can use this relationship'), |
|
|
); |
|
|
$form['submit'] = array( |
|
|
'#type' => 'submit', |
|
|
'#value' => 'Save', |
|
| 141 |
); |
); |
|
|
|
|
return $form; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Submit function for edit/delete a relationtype |
|
|
*/ |
|
|
function buddylist_ui_admin_form_edit_submit($form, &$form_state) { |
|
|
$res = new stdClass(); |
|
|
foreach(array('name', 'oneway', 'active', 'rtid') as $key) { |
|
|
$res->{$key} = $form_state['values'][$key]; |
|
|
} |
|
|
|
|
|
if(is_numeric($res->rtid)) |
|
|
drupal_set_message(t('Relation type has been updated')); |
|
|
else |
|
|
drupal_set_message(t('Relation type has been saved')); |
|
|
|
|
|
buddylist_api_rtype_save($res); |
|
|
|
|
|
$form_state['redirect'] = 'admin/buddylist/rtypes'; |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
* Returns the form for deleting a rtype |
|
|
*/ |
|
|
function buddylist_ui_admin_form_delete(&$form_state, $rtid = NULL) { |
|
|
if ($rtid) { |
|
|
$form['rtid'] = array( |
|
|
'#type' => 'value', |
|
|
'#value' => (int)$rtid->rtid, |
|
|
); |
|
|
|
|
|
return confirm_form( |
|
|
$form, |
|
|
t('Are you sure you want to delete %name?', array('%name' => $rtid->name)), |
|
|
'admin/buddylist/rtypes', |
|
|
t('This action cannot be undone.'), |
|
|
t('Delete'), t('Cancel') |
|
|
); |
|
|
} |
|
|
else { |
|
|
drupal_set_message(t('Donīt exists')); |
|
|
drupal_goto('admin/buddylist/rtypes'); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Submit function for deleting a relationtype |
|
|
*/ |
|
|
function buddylist_ui_admin_form_delete_submit($form, &$form_state) { |
|
|
buddylist_api_rtype_delete($form_state['values']['rtid']); |
|
|
drupal_set_message(t('Relationship has been deleted.')); |
|
|
$form_state['redirect'] = 'admin/buddylist/rtypes'; |
|
| 142 |
} |
} |