name);
// List of workitem types
$workitem_types = array();
$workitem_types['1'] = 'Issue';
$workitem_types['2'] = 'Release';
$workitem_types['3'] = 'Commit';
$workitem_types['4'] = 'Wiki';
$workitem_types['5'] = 'Blog';
$workitem_types['6'] = 'Comment';
asort($workitem_types);
// create workitem types in form
foreach ($workitem_types as $key => $value) {
$form['workitem'][$key] = array('#value' => t($value));
}
// Checkboxes and projects
foreach ($projects as $project) {
// get subscriptions
$subscriptions = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.list_workitem_subscription', (int)$project['id']);
// TODO check xmlrpc error
$form['project'][] = array(
'#value' => $project['name'],
'#id' => $project['id']
);
// search subscribed types in result and create default values for checkboxes
foreach ($workitem_types as $w_id => $w_name) {
// projectname-workitem_typeid (origo-3)
//$options = array();
//$options[$project['name'] . '-' . $w_id] = '';
// struct which should be in xml rpc call result if type is subscribed
$find['workitem_type'] = (int)$w_id;
$find['subscription_type'] = 1;
// create 'origo home' checkboxes
if (in_array($find, $subscriptions)) {
$form['checkboxes'][$project['name']][$w_id][$project['id'] .':'. $w_id .':1'] =
array(
'#type' => 'checkboxes',
'#options' => array(1 => t('')),
'#default_value' => array(1)
);
}
else {
$form['checkboxes'][$project['name']][$w_id][$project['id'] .':'. $w_id .':1'] =
array(
'#type' => 'checkboxes',
'#options' => array(1 => t('')),
);
}
// create 'mail notification' checkboxes
$find['subscription_type'] = 2;
if (in_array($find, $subscriptions)) {
$form['checkboxes'][$project['name']][$w_id][$project['id'] .':'. $w_id .':2'] =
array(
'#type' => 'checkboxes',
'#options' => array(1 => t('')),
'#default_value' => array(1)
);
}
else {
$form['checkboxes'][$project['name']][$w_id][$project['id'] .':'. $w_id .':2'] =
array(
'#type' => 'checkboxes',
'#options' => array(1 => t(''))
);
}
}
}
// Subscription types
$form['type_names']['show'] = array('#value' => t('Show on Origo Home'), '#tree' => TRUE);
$form['type_names']['mail'] = array('#value' => t('Mail Notification'), '#tree' => TRUE);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save subscriptions')
);
return $form;
}
function theme_origo_home_settings_subscriptions_form($form) {
// prerender the html code for each workitem type
foreach (element_children($form['workitem']) as $w_id) {
$workitem_types[$w_id] = drupal_render($form['workitem'][$w_id]);
}
$rows=array();
drupal_add_js("function setChecked(val, id, type) {for (i=1;i<7;i++){obj=document.getElementById('edit-'+id+':'+i+':'+type+'-1');obj.checked=val;}}", 'inline', 'footer', TRUE);
foreach (element_children($form['project']) as $project_key) {
// Don't take form control structures
if (is_array($form['project'][$project_key])) {
$row = array();
$project_id = $form['project'][$project_key]['#id'];
// render project name (multi-column)
$row[0][] = array('data' => t('@project', array('@project' => drupal_render($form['project'][$project_key]))), 'class' => 'module', 'id' => 'project-'. $form['project'][$project_key]['#value'], 'colspan' => count(element_children($form['workitem'])) + 2);
$row[1][] = array('data' => t($form['type_names']['show']['#value']), 'class' => 'subscriptions', 'id' => 'project-'. $project_key .'-1', 'style' => 'padding:0px 20px;font-size:11px');
$row[2][] = array('data' => t($form['type_names']['mail']['#value']), 'class' => 'subscriptions', 'id' => 'project-'. $project_key .'-2', 'style' => 'padding:0px 20px;font-size:11px');
$row[1][]= array('data' => ' ', 'align' => 'center');
$row[2][]= array('data' => ' ', 'align' => 'center');
foreach (element_children($form['workitem']) as $key) {
$projectname = $form['project'][$project_key]['#value'];
$i=1;
foreach (element_children($form['checkboxes'][$projectname][$key]) as $rid) {
if (is_array($form['checkboxes'][$projectname][$key][$rid])) {
$row[$i][] = array('data' => drupal_render($form['checkboxes'][$projectname][$key][$rid]), 'align' => 'center', 'title' => t($key));
$i++;
}
}
}
$rows = array_merge($rows, $row);
}
}
unset($form['type_names']);
$header[] = (t('Workitem Type'));
//foreach (element_children($form['type_names']) as $rid) {
$header[] = 'all';
foreach (element_children($form['workitem']) as $rid) {
// if (is_array($form['type_names'][$rid])) {
// $header[] = drupal_render($form['type_names'][$rid]);
$header[] = $workitem_types[$rid];
// }
}
$output = theme('table', $header, $rows, array('id' => 'subscriptions'));
$output .= drupal_render($form);
return $output;
}
function origo_home_settings_subscriptions_form_submit($form, &$form_state) {
$subscriptions = array();
foreach ($form_state['values'] as $key => $value) {
$item = explode(':', $key);
if (count($item) == 3) {
$subscriptions[$item[0]][] = array('workitem_type' => (int)$item[1], 'subscription_type' => (int)$item[2], 'is_enabled' => $value[1] == 1);
}
}
$error_msg = '';
foreach ($subscriptions as $project_id => $subscription) {
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.set_workitem_subscription', (int)$project_id, $subscription);
if (xmlrpc_errno() > 0) {
$error_msg .= t(xmlrpc_error_msg() .' ');
}
}
if (drupal_strlen($error_msg) > 0) {
drupal_set_message(t('The following error(s) occured: '. $error_msg), 'error');
}
else {
drupal_set_message(t('The changes have been saved.'));
}
}
/**
* Bookmark settings page
*/
function origo_home_settings_bookmarks_page() {
global $user;
$output = '';
// Origo API call to get projects
$projects = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.list_bookmark', $user->name);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
else {
$header = array(array('data' => t('Project'), 'colspan' => '3'));
$rows = array();
// sort the list
usort($projects, "_cmp_names");
$webdomain = variable_get('origo_web_domain', '');
//TODO: reuse code of pager_query
foreach ($projects as $project) {
$linkbutton =
l(
' ',
get_origo_project_link($project['name']),
array('html' => TRUE)
);
$project_link = l($project['name'], get_origo_project_link($project['name']));
$removelink = l('[Remove Bookmark]', 'origo_home/bookmarks/remove/'. $project['project_id']);
$manage_link = '';
if (user_access('origo admin access')) {
$manage_link = l(' [Manage Project]', get_origo_project_link($project['name']) .'/project_settings');
}
$row = array();
$row[] = array(
'data' => $linkbutton,
'width' => '40',
'style' => 'height:35px'
);
$row[] = array(
'data' => $project_link,
'width' => '50%',
'style' => 'height:35px'
);
$row[] = array(
'data' => $removelink . $manage_link,
'style' => 'height:35px'
);
$rows[] = $row;
}
// Show table
$output .= theme('table', $header, $rows, array('style' => 'width:100%'));
}
return $output;
}
/**
* User Key settings page
*
* @return String
*/
function origo_home_settings_userkey_page() {
$output = '';
$output .= t('Your user key: ');
$key = origo_auth_xmlrpc_session(variable_get('origo_api_internal', ''), 'internal_user.key');
if (empty($key)) {
$output .= t('-- no user key assigned --');
}
else {
$output .= t($key);
}
$output .= t(' ');
$output .= drupal_get_form('origo_home_settings_userkey_form');
return $output;
}
function origo_home_settings_userkey_form(&$form_state) {
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Request new user key'),
);
return $form;
}
function origo_home_settings_userkey_form_submit($form, &$form_state) {
$key = origo_auth_xmlrpc_session(variable_get('origo_api_internal', ''), 'internal_user.generate_key');
drupal_set_message(t('Key requested.'));
}
/**
* Display user password settings page
*/
function origo_home_settings_password_form(&$form_state) {
// add Drupal password strength check
_user_password_dynamic_validation();
$form['pass'] = array(
'#type' => 'password_confirm',
'#description' => t('To change the current user password, enter the new password in both fields. The size for the password is limited to 50 characters.'),
'#required' => TRUE,
'#size' => 25,
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function origo_home_settings_password_form_validate($form, &$form_state) {
if (drupal_strlen($form_state['values']['pass']) > 50) {
form_set_error('pass', t('Your password is longer than 50 characters.'));
}
}
function origo_home_settings_password_form_submit($form, &$form_state) {
global $user;
$test = origo_auth_xml_rpc(variable_get('origo_api_internal', ''), 'internal_user.change_password', $user->name, $form_state['values']['pass']);
if ((int)xmlrpc_errno() > 0) {
form_set_error('pass', t(xmlrpc_error_msg()));
}
else {
origo_auth_authenticate($user->name, $form_state['values']['pass']);
drupal_set_message(t('Password saved.'));
}
}
/**
* Display user icon page
*
* @return user icon page
*/
function origo_home_settings_user_icon_page() {
$output = t('Your user icon is visible to every other Origo user. ');
$output .= drupal_get_form('origo_home_settings_user_icon_form');
return $output;
}
function origo_home_settings_user_icon_form(&$form_state) {
global $user;
drupal_set_title('Edit User Icon');
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['user_icon'] = array(
'#title' => t('New User Icon'),
'#type' => 'file',
'#description' => t('Don\'t use spaces in the filename. The icon will be reduced to a max size of 200x600px.'),
);
$form['upload'] = array(
'#type' => 'submit',
'#value' => t('Upload New Icon'),
);
$form['reset'] = array(
'#type' => 'submit',
'#value' => t('Reset Icon'),
);
return $form;
}
function theme_origo_home_settings_user_icon_form($form) {
$output = '
';
$output .= drupal_render($form);
$output .= '
';
return $output;
}
function origo_home_icon_upload_validate(&$file) {
$errors = array();
if (drupal_strlen($filename) > 255) {
$errors[] = t('Filename mustn\'t be longer than 255 chars.');
}
return $errors;
}
function origo_home_settings_user_icon_form_submit($form, &$form_state) {
global $user;
if ($form_state['values']['op'] == 'Upload New Icon') {
// first, check the file-to-upload
$validators = array(
'file_validate_is_image' => array(),
'origo_home_icon_upload_validate' => array()
);
$source = file_save_upload('user_icon', $validators);
if ($source == 0) {
form_set_error('upload', t('Error while uploading image.'));
}
else {
// drupal accepted the file, let's upload it to origo
$connection_id = ftp_connect(variable_get('origo_ftp', ''));
$pass = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.my_password');
if (ftp_login($connection_id, $user->name, $pass)) {
$uploaded = FALSE;
if (ftp_put($connection_id, $source->filename, $source->filepath, FTP_BINARY)) {
$uploaded = TRUE;
}
// API call to set user icon
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.set_icon', $source->filename);
if ($uploaded && (int)xmlrpc_errno() > 0) {
form_set_error('upload', t('Error while uploading: '. xmlrpc_error_msg()));
}
else {
drupal_set_message(t('User Icon uploaded.'));
}
}
}
}
elseif ($form_state['values']['op'] == 'Reset Icon') {
// Restore the default user picture
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.reset_icon');
if ((int)xmlrpc_errno() > 0) {
form_set_error('reset', t('The following error occured: '. xmlrpc_error_msg()));
}
else {
drupal_set_message(t('User Icon reset.'));
}
}
}
/**
* Display user personal information page with basic information
*
* @return user personal information page
*/
function origo_home_settings_personal_information_page() {
$output = t('Here you can edit general information about you. ');
$output .= t('Personal information is visible to every Origo user.');
$output .= drupal_get_form('origo_home_settings_personal_information_form');
return $output;
}
function origo_home_settings_personal_information_form(&$form_state) {
global $user;
drupal_set_title('Edit Personal Information');
$user_information = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.retrieve_information', $user->name);
$form['first_name'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#default_value' => t($user_information['first_name']),
'#size' => 30,
'#maxlength' => 50,
);
$form['last_name'] = array(
'#type' => 'textfield',
'#title' => t('Last Name'),
'#default_value' => t($user_information['last_name']),
'#size' => 30,
'#maxlength' => 50,
);
$form['gender'] = array(
'#type' => 'select',
'#title' => t('Gender'),
'#options' => array(
'male' => t('Male'),
'female' => t('Female'),
),
'#default_value' => t($user_information['gender']),
);
$form['languages'] = array(
'#type' => 'textfield',
'#title' => t('Languages'),
'#default_value' => t($user_information['languages']),
'#description' => t('Comma separated list of languages.'),
'#size' => 50,
'#maxlength' => 250,
);
$birthday = explode(' ', $user_information['birthday']);
$birthday = explode('/', $birthday[0]);
$birthday_year = $birthday[2];
$birthday_month = $birthday[0];
$birthday_day = $birthday[1];
for ($i = 1900; $i <= (int)date('Y'); $i++) {
$years[$i] = t((string)$i);
}
$form['birthday_year'] = array(
'#type' => 'select',
'#title' => 'Birthday',
'#options' => $years,
'#attributes' => array('class' => 'birthday_year'),
'#default_value' => t((int)$birthday_year),
);
$months = array(
'1' => t('January'),
'2' => t('February'),
'3' => t('March'),
'4' => t('April'),
'5' => t('May'),
'6' => t('June'),
'7' => t('July'),
'8' => t('August'),
'9' => t('September'),
'10' => t('October'),
'11' => t('November'),
'12' => t('December'),
);
$form['birthday_month'] = array(
'#type' => 'select',
'#options' => $months,
'#attributes' => array('class' => 'birthday_month'),
'#default_value' => t((int)$birthday_month),
);
for ($i = 1; $i <= 31; $i++) {
if ($i < 10) {
$days[$i] = t('0'. (string)$i);
}
else {
$days[$i] = t((string)$i);
}
}
$form['birthday_day'] = array(
'#type' => 'select',
'#options' => $days,
'#attributes' => array('class' => 'birthday_day'),
'#default_value' => t((int)$birthday_day),
);
$form['timezone'] = array(
'#type' => 'textfield',
'#title' => t('Timezone'),
'#default_value' => t($user_information['timezone']),
'#size' => 10,
'#description' => t('For example "CET" or "GMT+2".'),
);
$form['homepage'] = array(
'#type' => 'textfield',
'#title' => t('Homepage'),
'#default_value' => t($user_information['homepage']),
'#size' => 50,
'#maxlength' => 100,
);
$form['blog'] = array(
'#type' => 'textfield',
'#title' => t('Blog'),
'#default_value' => t($user_information['blog']),
'#size' => 50,
'#maxlength' => 100,
);
$form['ohloh_profile'] = array(
'#type' => 'textfield',
'#title' => t('Ohloh Profile'),
'#default_value' => t($user_information['ohloh_profile']),
'#description' => t('Link to your ohloh profile (http://www.ohloh.net/accounts/xxxx).'),
'#size' => 50,
'#maxlength' => 100,
);
$form['signature'] = array(
'#type' => 'textarea',
'#title' => t('Forum Signature'),
'#default_value' => t($user_information['signature']),
);
$form['message'] = array(
'#type' => 'textarea',
'#title' => t('Message To The World'),
'#default_value' => t($user_information['message']),
);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function theme_origo_home_settings_personal_information_form($form) {
$output = '';
$output .= drupal_render($form);
$output .= '
';
return $output;
}
function origo_home_settings_personal_information_form_submit($form, &$form_state) {
global $user;
if ($form_state['values']['op'] == 'Save') {
$user_information_old = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.retrieve_information', $user->name);
$user_email_old = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.my_email');
// gather changed data
if ($form_state['values']['first_name'] != $user_information_old['first_name']) {
$changed_information[] = array(
'information_type' => 'first_name',
'information_value' => $form_state['values']['first_name'],
);
};
if ($form_state['values']['last_name'] != $user_information_old['last_name']) {
$changed_information[] = array(
'information_type' => 'last_name',
'information_value' => $form_state['values']['last_name'],
);
}
if ($form_state['values']['gender'] != $user_information_old['gender']) {
$changed_information[] = array(
'information_type' => 'gender',
'information_value' => $form_state['values']['gender'],
);
}
if ($form_state['values']['languages'] != $user_information_old['languages']) {
$changed_information[] = array(
'information_type' => 'languages',
'information_value' => $form_state['values']['languages'],
);
}
$birthday = explode(' ', $user_information_old['birthday']);
$birthday = explode('/', $birthday[0]);
$birthday_year = $birthday[2];
$birthday_month = $birthday[0];
$birthday_day = $birthday[1];
if (($form_state['values']['birthday_year'] != $birthday_year) ||
($form_state['values']['birthday_month'] != $birthday_month) ||
($form_state['values']['birthday_day'] != $birthday_day)
) {
$new_birthday = $form_state['values']['birthday_year'] .'-'. $form_state['values']['birthday_month'] .'-'. $form_state['values']['birthday_day'];
$changed_information[] = array(
'information_type' => 'birthday',
'information_value' => $new_birthday,
);
}
if ($form_state['values']['timezone'] != $user_information_old['timezone']) {
$changed_information[] = array(
'information_type' => 'timezone',
'information_value' => $form_state['values']['timezone'],
);
}
if ($form_state['values']['signature'] != $user_information_old['signature']) {
$changed_information[] = array(
'information_type' => 'signature',
'information_value' => $form_state['values']['signature'],
);
}
if ($form_state['values']['message'] != $user_information_old['message']) {
$changed_information[] = array(
'information_type' => 'message',
'information_value' => $form_state['values']['message'],
);
}
if ($form_state['values']['homepage'] != $user_information_old['homepage']) {
$changed_information[] = array(
'information_type' => 'homepage',
'information_value' => $form_state['values']['homepage'],
);
}
if ($form_state['values']['blog'] != $user_information_old['blog']) {
$changed_information[] = array(
'information_type' => 'blog',
'information_value' => $form_state['values']['blog'],
);
}
if ($form_state['values']['ohloh_profile'] != $user_information_old['ohloh_profile']) {
$changed_information[] = array(
'information_type' => 'ohloh_profile',
'information_value' => $form_state['values']['ohloh_profile'],
);
}
// send user.set_information api call if necessary
if (count($changed_information) > 0) {
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.set_information', $changed_information);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
else {
drupal_set_message(t('Personal information saved.'));
}
}
}
}
/**
* Display user contact information page with basic contact information
* of the user: email, icq, skype, jabber, yahoo, msn, etc.
*
* @return user contact information page
*/
function origo_home_settings_contact_information_page() {
$output = t('Here you can edit contact information about you. ');
$output .= t('Contact information (except your e-mail address) is visible to every Origo user.');
$output .= drupal_get_form('origo_home_settings_contact_information_form');
return $output;
}
function origo_home_settings_contact_information_form(&$form_state) {
global $user;
drupal_set_title('Edit Contact Information');
$user_information = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.retrieve_information', $user->name);
$user_email = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.my_email');
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('E-mail Address'),
'#description' => t('Your e-mail address will not be displayed in your User Profile.'),
'#default_value' => t($user_email),
'#required' => TRUE,
'#size' => 30,
'#maxlength' => 100,
);
$form['icq'] = array(
'#type' => 'textfield',
'#title' => t('ICQ'),
'#default_value' => t($user_information['icq']),
'#size' => 30,
'#maxlength' => 10,
);
$form['jabber'] = array(
'#type' => 'textfield',
'#title' => t('Jabber'),
'#default_value' => t($user_information['jabber']),
'#size' => 30,
'#maxlength' => 50,
);
$form['aim'] = array(
'#type' => 'textfield',
'#title' => t('AIM'),
'#default_value' => t($user_information['aim']),
'#size' => 30,
'#maxlength' => 50,
);
$form['yahoo'] = array(
'#type' => 'textfield',
'#title' => t('Yahoo'),
'#default_value' => t($user_information['yahoo']),
'#size' => 30,
'#maxlength' => 50,
);
$form['msn'] = array(
'#type' => 'textfield',
'#title' => t('MSN'),
'#default_value' => t($user_information['msn']),
'#size' => 30,
'#maxlength' => 50,
);
$form['skype'] = array(
'#type' => 'textfield',
'#title' => t('Skype'),
'#default_value' => t($user_information['skype']),
'#size' => 30,
'#maxlength' => 50,
);
$form['irc'] = array(
'#type' => 'textfield',
'#title' => t('IRC'),
'#default_value' => t($user_information['irc']),
'#size' => 30,
'#maxlength' => 50,
);
$form['sip'] = array(
'#type' => 'textfield',
'#title' => t('SIP Number'),
'#default_value' => t($user_information['sip']),
'#size' => 30,
'#maxlength' => 50,
);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function theme_origo_home_settings_contact_information_form($form) {
$output = '';
$output .= drupal_render($form);
$output .= '
';
return $output;
}
function origo_home_settings_contact_information_form_submit($form, &$form_state) {
global $user;
if ($form_state['values']['op'] == 'Save') {
$user_information_old = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.retrieve_information', $user->name);
$user_email_old = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.my_email');
if ($form_state['values']['icq'] != $user_information_old['icq']) {
$changed_information[] = array(
'information_type' => 'icq',
'information_value' => $form_state['values']['icq'],
);
}
if ($form_state['values']['aim'] != $user_information_old['aim']) {
$changed_information[] = array(
'information_type' => 'aim',
'information_value' => $form_state['values']['aim'],
);
}
if ($form_state['values']['jabber'] != $user_information_old['jabber']) {
$changed_information[] = array(
'information_type' => 'jabber',
'information_value' => $form_state['values']['jabber'],
);
}
if ($form_state['values']['yahoo'] != $user_information_old['yahoo']) {
$changed_information[] = array(
'information_type' => 'yahoo',
'information_value' => $form_state['values']['yahoo'],
);
}
if ($form_state['values']['msn'] != $user_information_old['msn']) {
$changed_information[] = array(
'information_type' => 'msn',
'information_value' => $form_state['values']['msn'],
);
}
if ($form_state['values']['skype'] != $user_information_old['skype']) {
$changed_information[] = array(
'information_type' => 'skype',
'information_value' => $form_state['values']['skype'],
);
}
if ($form_state['values']['irc'] != $user_information_old['irc']) {
$changed_information[] = array(
'information_type' => 'irc',
'information_value' => $form_state['values']['irc'],
);
}
if ($form_state['values']['sip'] != $user_information_old['sip']) {
$changed_information[] = array(
'information_type' => 'sip',
'information_value' => $form_state['values']['sip'],
);
}
// send user.set_information api call if necessary
if (count($changed_information) > 0) {
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.set_information', $changed_information);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
else {
drupal_set_message(t('Account details saved.'));
}
}
// check email address and send user.change_email api call if necessary
if ($form_state['values']['email'] != $user_email_old) {
origo_auth_xmlrpc_session(variable_get('origo_api_internal', ''), 'internal_user.change_email', $form_state['values']['email']);
if ((int)xmlrpc_errno() > 0) {
form_set_error('email', t(xmlrpc_error_msg()));
}
else {
drupal_set_message(t('E-mail saved.'));
}
}
}
}
/**
* Additional Settings
*
* @return output formatted form string
*/
function origo_home_additional_settings_page() {
$output = t('Here you can edit some additional account settings. ');
$output .= drupal_get_form('origo_home_additional_settings_form');
return $output;
}
// additional account settings form
function origo_home_additional_settings_form(&$form_state) {
global $user;
drupal_set_title('Privacy Settings');
$old_profile_visible = origo_auth_xml_rpc(variable_get('origo_api', ''), 'user.profile_visible', $user->name);
$form = array();
$form['name'] = array(
'#type' => 'fieldset',
'#title' => t('Privacy Settings'),
'#weight' => 0,
);
// this is an ugly hack
$form['name']['spacer'] = array(
'#type' => 'markup',
'#value' => '
',
);
$form['name']['profile_visible'] = array(
'#type' => 'checkbox',
'#default_value' => $old_profile_visible['profile_visible'],
'#title' => t('Profile visible for visitors'),
);
$form['save'] = array(
'#type' => 'submit',
'#value' => t('Save'),
'#weight' => 9,
);
return $form;
}
function theme_origo_home_additional_settings_form($form) {
$output = '';
$output .= drupal_render($form);
$output .= '
';
return $output;
}
function origo_home_additional_settings_form_submit($form, &$form_state) {
global $user;
if ($form_state['values']['op'] == 'Save') {
// get the array from the database
$old_profile_visible = origo_auth_xml_rpc(variable_get('origo_api', ''), 'user.profile_visible', $user->name);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
else {
$new_value = $old_profile_visible['encoded'];
// check if the value has to be updated
if ($form_state['values']['profile_visible'] != $old_profile_visible['profile_visible']) {
// update first bit to $form_state['values']['profile_visible']
$new_value = ($old_profile_visible['profile_visible'])?$new_value-1:$new_value+1;
}
if ($new_value != $old_profile_visible['encoded']) {
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.change_profile_visible', $new_value);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
else {
drupal_set_message(t('The settings have been saved'));
}
}
}
}
}
/**
* Disable Account Page
*
* @return String disable account form
*/
function origo_home_settings_disable_account_page() {
global $user;
$output = t('Do you really want to permanently disable your Origo account? ');
$output .= t('This action can not be undone!');
$output .= drupal_get_form('origo_home_settings_disable_account_form', $user->name);
return $output;
}
function origo_home_settings_disable_account_form(&$form_state, $user_name) {
$form['user_name'] = array(
'#type' => 'hidden',
'#value' => $user_name,
);
$form['confirm'] = array(
'#type' => 'submit',
'#value' => t('Disable Account'),
);
return $form;
}
function origo_home_settings_disable_account_form_submit($form, &$form_state) {
if ($form_state['values']['op'] == t('Disable Account')) {
$user_name = $form_state['values']['user_name'];
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.disable_account', $user_name);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error has occured: '. xmlrpc_error_msg()), 'error');
}
else {
drupal_set_message(t('Successfully disabled your Origo account.'));
// destroy the Origo cookie on logout
setcookie('origo_session', '', time() - 42000, '/', variable_get('origo_cookie_domain', ''));
// need include for calling `user_logout'
include(drupal_get_path('module', 'user') .'/user.pages.inc');
user_logout();
}
}
}
// Personal Settings - Origo Web - Workitem
function origo_home_settings_workitem_settings_form(&$form_state) {
global $user;
$usr_wi_per_page = variable_get(ORIGO_WORKITEM_AMOUNT .'_'. $user->name, 32);
$usr_rss_show_unread = variable_get(ORIGO_FEED_SHOW_UNREAD .'_'. $user->name, 25);
$form['workitem_amount'] = array(
'#type' => 'textfield',
'#title' => t('Workitem display amount'),
'#default_value' => $usr_wi_per_page,
'#size' => 2,
'#maxlength' => 2,
'#description' => t('The amount of workitems to display per project in your workitem browser. High values may affect loading times.'),
);
$form['rss_show_unread'] = array(
'#type' => 'checkbox',
'#title' => 'Show read workitems in RSS feed',
'#default_value' => $usr_rss_show_unread,
'#description' => t('This setting controls whether your RSS feeds - the general feed as well as the project-specific ones - will display workitems that you already read on Origo.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
$form['cancel'] = array(
'#type' => 'button',
'#attributes' => array('onClick' => 'location.replace("'. referer_uri() .'"); return false;'),
'#value' => t('Cancel'),
);
return $form;
}
function origo_home_settings_workitem_settings_form_validate($form, &$form_state) {
if (!is_numeric($form_state['values']['workitem_amount']) || (int)$form_state['values']['workitem_amount'] <= 0) {
form_set_error('', t('Workitem amount must be a positive integer.'));
}
if ((int)$form_state['values']['workitem_amount'] > 4294967295) { // Mysql max int
form_set_error('', t('Workitem amount mustn\'t exceed maximum integer range.'));
}
}
function origo_home_settings_workitem_settings_form_submit($form, &$form_state) {
global $user;
$current_amount = variable_get(ORIGO_WORKITEM_AMOUNT .'_'. $user->name, -1);
$wi_amount = (int)$form_state['values']['workitem_amount'];
$current_rss_flag = variable_get(ORIGO_FEED_SHOW_UNREAD .'_'. $user->name, -1);
$rss_flag = (bool)$form_state['values']['rss_show_unread'];
$changed_information = NULL;
if ($wi_amount != $current_amount) {
// store/cache in the front-end
variable_set(ORIGO_WORKITEM_AMOUNT .'_'. $user->name, $wi_amount);
$changed_information[] = array(
'information_type' => 'workitems_per_page',
'information_value' => $wi_amount,
);
}
if ($rss_flag != $current_rss_flag) {
// store/cache in the front-end
variable_set(ORIGO_FEED_SHOW_UNREAD .'_'. $user->name, $rss_flag);
$changed_information[] = array(
'information_type' => 'feed_show_unread',
'information_value' => $rss_flag,
);
}
// send user.set_information api call if necessary
if (isset($changed_information) && count($changed_information) > 0) {
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.set_information', $changed_information);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
}
// Always show "saved" message, regardless whether we actually did anything or not.
drupal_set_message(t('Workitem settings saved.'));
}
// ---------------------------------------------------------------------------------------------------------
// Personal Settings - Issues
function origo_home_settings_issues_form(&$form_state) {
global $user;
$usr_issues_per_page = variable_get(ORIGO_ISSUE_AMOUNT .'_'. $user->name, 25);
$form['issues_amount'] = array(
'#type' => 'textfield',
'#title' => t('Issues per Page'),
'#default_value' => $usr_issues_per_page,
'#size' => 2,
'#maxlength' => 2,
'#description' => t('The amount of issues to list in the issue tracker and reported issues page. High values may affect loading times.'),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}
function origo_home_settings_issues_form_validate($form, &$form_state) {
if (!is_numeric($form_state['values']['issues_amount']) || (int)$form_state['values']['issues_amount'] < 1) {
form_set_error('issues_amount', t('Issues per page must be at least 1.'));
}
if ((int)$form_state['values']['issues_amount'] > 4294967295) { // Mysql max int
form_set_error('issues_amount', t('Issues per page mustn\'t exceed maximum integer range.'));
}
}
function origo_home_settings_issues_form_submit($form, &$form_state) {
global $user;
$current_value = variable_get(ORIGO_ISSUE_AMOUNT .'_'. $user->name, -1);
$issues_amount = (int)$form_state['values']['issues_amount'];
if ($issues_amount != $current_value) {
// store/cache in the front-end
variable_set(ORIGO_ISSUE_AMOUNT .'_'. $user->name, $issues_amount);
$changed_information[] = array(
'information_type' => 'issues_per_page',
'information_value' => $issues_amount,
);
// send user.set_information api call if necessary
if (count($changed_information) > 0) {
origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.set_information', $changed_information);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
}
}
// Always show "saved" message, regardless whether we actually did anything or not.
drupal_set_message(t('Issue settings saved.'));
}
// ---------------------------------------------------------------------------------------------------------
/**
* Dashboard for user settings.
*
* @return String dashboard settings page.
*/
function origo_home_settings_dashboard_page() {
$data = array(
'colleft' => array(
'Account Administration' => array(
array(
'title' => 'User Key',
'link' => 'origo_home/settings/userkey',
'description' => 'Manage your user keys for use with Origo\'s external tools.',
),
array(
'title' => 'Request Application Key',
'link' => 'origo_home/request_appkey',
'description' => 'Request an application key for connecting your application to Origo\'s API.',
),
array(
'title' => 'Password',
'link' => 'origo_home/settings/password',
'description' => 'Set your new Origo password.',
),
array(
'title' => 'Disable Account',
'link' => 'origo_home/settings/disable_account',
'description' => 'Disable your Origo account permanently.',
),
),
'Projects' => array(
array(
'title' => 'Subscriptions',
'link' => 'origo_home/settings/subscriptions',
'description' => 'View and edit your workitem subscriptions.',
),
array(
'title' => 'Workitems',
'link' => 'origo_home/settings/workitems',
'description' => 'Adjust the number of listed workitems on a single page in your dashboard.',
),
array(
'title' => 'Issues',
'link' => 'origo_home/settings/issues',
'description' => 'Adjust settings for issues, e.g. the number of issues listed in the issue tracker.',
),
array(
'title' => 'Bookmarks',
'link' => 'origo_home/settings/bookmarks',
'description' => 'View and manage your bookmarks.',
),
),
),
'colright' => array(
'Account Details' => array(
array(
'title' => 'Personal Information',
'link' => 'origo_home/settings/personal_information',
'description' => 'View and edit your personal information.',
),
array(
'title' => 'User Icon',
'link' => 'origo_home/settings/user_icon',
'description' => 'Set your new user icon or reset your user icon to the template user icon.',
),
array(
'title' => 'Contact Information',
'link' => 'origo_home/settings/contact_information',
'description' => 'View and edit your contact information (e-mail, IM, VoIP).',
),
array(
'title' => 'Privacy',
'link' => 'origo_home/settings/additional_settings',
'description' => 'Manage your privacy settings.',
),
),
'Communities' => array(
array(
'title' => 'Communities',
'link' => 'origo_home/settings/communities',
'description' => 'View and manage your communities.',
),
),
),
);
return theme("dashboard_settings", $data);
}
/**
* Theme the settings dashboard page, i.e. generate HTML code for data provided by $items.
* @param Array $items Complex, associative array containing the data to display.
* @return String The HTML code to emit.
*/
function theme_dashboard_settings($items) {
$output = "\n";
foreach ($items as $column => $data) {
$output .= "\t
\n";
foreach ($data as $section => $section_item) {
$output .= "\t\t
\n\t\t\t\n";
foreach ($section_item as $title => $item) {
$output .= "\t\t\t
\n\t\t\t\t\t". l(t($item['title']), $item['link']) ."\n\t\t\t
\n";
$output .= "\t\t\t
\n\t\t\t\t" . t($item['description']) . "\n\t\t\t
\n";
}
$output .= "\t\t
\n"; // end section
} // end sections
$output .= "\t
\n"; // end column
} // end columns
$output .= "
\n"; // end dashboard
return $output;
}
/**
* Communities settings page
*/
function origo_home_settings_communities_page() {
global $user;
// TODO marcozi
// code cleanup
$output = '';
// Origo API call to get communities
$communities = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.list_communities', $user->name);
if ((int)xmlrpc_errno() > 0) {
drupal_set_message(t('The following error occured: '. xmlrpc_error_msg()), 'error');
}
else {
$header = array(
array(
'data' => t('Community'),
// 'colspan' => '1'
),
array(
'data' => t('Operations'),
'colspan' => '1'
)
);
$rows = array();
// sort the list
usort($communities, "_cmp_names");
foreach ($communities as $community) {
$link = l($community['name'], 'communities/'. drupal_strtolower($community['name']));
$removelink = l('[Cancel Membership]', 'communities/'. $community['name'] .'/leave');
$row = array();
$row[] = array(
'data' => $link,
'width' => '50%',
//'style' => 'height:35px'
);
$row[] = array(
'data' => $removelink,
'width' => '50%',
//'style' => 'height:35px'
);
$rows[] = $row;
}
// Show table
$output .= theme('table', $header, $rows, array('style' => 'width:100%'));
}
return $output;
}
/**
* Utility function to retrieve user-settings.
* The function will try to exploit values cached in the front-end, sending API calls when necessary.
*
* @param string $setting The name of the setting to retrieve
* @param string $user_name The name of the user for which to retrieve the setting for.
* @return undefined The retrieved setting.
*/
function get_origo_setting($setting, $default_value, $user_name = NULL) {
// TODO: At the moment, front-end caching of user-settings is only implemented for "origo_home_workitem_amount"
// We thus return the default value for all other settings.
// TODO 2010-06-08: The variables retrieved by this functions have to adhere to some naming rules:
// - start with "origo_home_"
// - end with the setting name used by the backend (most often the same as the column-name of `user_information`
if (strpos($setting, ORIGO_SETTING_PREFIX) != 0) {
return $default_value;
}
if (!isset($user_name)) {
// Assume the retrival to be for the user currently logged in.
global $user;
$user_name = $user->name;
}
$cached_value = variable_get($setting ."_". $user_name, -1);
if ($cached_value === -1) {
// The value was not found in the front-end database.
// Get it from the back-end.
$user_information = origo_auth_xmlrpc_session(variable_get('origo_api', ''), 'user.retrieve_information', $user_name);
// The backend doesn't use the prefix.
$setting_suffix = drupal_substr($setting, drupal_strlen(ORIGO_SETTING_PREFIX));
$retrieved_value = $user_information[$setting_suffix];
if ((int)xmlrpc_errno() == 0 && $user_information != FALSE && $retrieved_value > 0) {
// cache the value in the front-end
variable_set($setting ."_". $user_name, $retrieved_value);
// return it
return $retrieved_value;
}
else {
// the setting wasnt found in the backend - use default value
return $default_value;
}
}
return $cached_value;
}