/** * E-mail address update form submit */ function guifi_tools_mail_update_form_submit($form, &$form_state) { global $user; guifi_log(GUIFILOG_TRACE, 'guifi_tools_mail_update_submit()', $form_state['values']); // perform the massive update to the granted rows, using guifi db api // instead of straight SQL to create the notificaton messages. $tables = array('guifi_zone', 'guifi_location', 'guifi_devices', 'guifi_services', 'guifi_users'); foreach ($tables as $table) { $sqlm = db_query('SELECT * FROM {%s} WHERE notification LIKE "%s"', $table, $form_state['values']['mail_search']); while ($amails = db_fetch_object($sqlm)) { // Check that the user has update access and creates the link $continue = FALSE; if (!user_access('administer guifi networks')) { switch ($table) { case 'guifi_users': $title = $amails->username; $type = t('User'); if (guifi_user_access('update', $amails->id)) { $continue = TRUE; } break; case 'guifi_devices': $title = $amails->nick; $type = t('Device'); if (guifi_device_access('update', $amails->id)) { $continue = TRUE; } break; case 'guifi_zone': $title = $amails->nick; $type = t('Zone'); if (guifi_zone_access('update', $amails->id)) { $continue = TRUE; } break; case 'guifi_location': $title = $amails->nick; $type = t('Node'); if (guifi_node_access('update', $amails->id)) { $continue = TRUE; } break; case 'guifi_service': $title = $amails->nick; $type = t('Service'); if (guifi_service_access('update', $amails->id)) { $continue = TRUE; } break; } } else { $continue = TRUE; } if (!$continue) { continue; } // here we have update access, so perform the update // Notify prevuious mail id, just in case... $to_mail = $amails->notification; $amails->notification = str_ireplace($form_state['values']['mail_search'], strtolower($form_state['values']['mail_replacewith']), $amails->notification); if ($to_mail == $amails->notification) { //no changes, so next continue; } $n = _guifi_db_sql($table, array('id' => $amails->id), (array) $amails, $log, $to_mail); guifi_notify($to_mail, t('The notification %notify for %type %title has been CHANGED to %new by %user.', array('%notify' => $form_state['values']['mail_search'], '%new' => $form_state['values']['mail_replacewith'], '%type' => $type, '%title' => $title, '%user' => $user->name)), $log); } // foreach row with the email found } // foreach table drupal_goto('guifi/menu/ip/mailsearch/' . $form_state['values']['mail_replacewith']); }
function guifi_users_queue($zone) { function _guifi_user_queue_device_form($form_state, $d = array()) { guifi_log(GUIFILOG_TRACE, 'function guifi_user_queue_device_form()', $d); if (count($d['radios']) != 1) { return; } if ($d['radios'][0]['mode'] != 'client') { return; } if (!isset($d['radios'][0]['interfaces'])) { return; } $iid = key($d['radios'][0]['interfaces']); if (!isset($d['radios'][0]['interfaces'][$iid]['ipv4'][0]['links'])) { return; } $lid = key($d['radios'][0]['interfaces'][$iid]['ipv4'][0]['links']); if (empty($iid) or empty($lid)) { return; } if (empty($form_state['values'])) { $form_state['values'] = $d; } $f['flag'] = array('#type' => 'item', '#value' => $form_state['values']['flag'], '#prefix' => '<table><tr><td>', '#suffix' => '</td>'); $f['mac'] = array('#type' => 'textfield', '#required' => TRUE, '#size' => 17, '#maxlength' => 17, '#default_value' => $form_state['values']['radios'][0]['mac'], '#element_validate' => array('guifi_mac_validate'), '#prefix' => '<td>', '#suffix' => '</td>'); $f['did'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']); $f['nid'] = array('#type' => 'hidden', '#value' => $form_state['values']['nid']); $f['uid'] = array('#type' => 'hidden', '#value' => $form_state['values']['uid']); $f['iid'] = array('#type' => 'hidden', '#value' => $iid); $f['lid'] = array('#type' => 'hidden', '#value' => $lid); $f['approve'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/ok.png', '#attributes' => array('title' => t('Set the device and link Online, confirm MAC & approve user.')), '#prefix' => '<td>', '#suffix' => '</td></tr></table>'); return $f; } function _guifi_user_queue_form($form_state, $params = array()) { guifi_log(GUIFILOG_TRACE, 'function guifi_user_queue_form()', $params); if (empty($form_state['values'])) { $form_state['values'] = $params; } $f['status'] = array('#type' => 'select', '#options' => guifi_types('user_status'), '#default_value' => $form_state['values']['status'], '#prefix' => '<table><tr><td>', '#suffix' => '</td>'); $f['uid'] = array('#type' => 'hidden', '#value' => $form_state['values']['id']); $f['saveUser'] = array('#type' => 'image_button', '#src' => drupal_get_path('module', 'guifi') . '/icons/save.png', '#attributes' => array('title' => t('Change & Save users Status.')), '#submit' => array('_guifi_user_queue_device_form_submit'), '#prefix' => '<td>', '#suffix' => '</td></tr></table>'); return $f; } function _guifi_user_queue_devices($u) { $query = db_query('SELECT d.id ' . 'FROM {guifi_devices} d ' . 'WHERE d.nid=%d' . ' AND type="radio"', $u['nid']); $rows = array(); while ($d = db_fetch_array($query)) { $d = guifi_device_load($d['id']); $d['uid'] = $u['id']; if (guifi_device_access('update', $d['id'])) { $edit_device_icon = l(guifi_img_icon('edit.png'), 'guifi/device/' . $d['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/device/' . $d['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank'))); } else { $edit_device_icon = ''; } if (user_access('administer guifi users')) { $edit_ok_icon = drupal_get_form('_guifi_user_queue_device_form', $d); } else { $edit_ok_icon = $d['flag']; if (count($d['radios']) == 1 and $d['radios'][0]['mode'] == 'client') { $edit_ok_icon .= ' ' . $d['radios'][0]['mac']; } } $ip = guifi_main_ip($d['id']); $status_url = guifi_cnml_availability(array('device' => $d['id'], 'format' => 'short')); $rows[] = array($edit_device_icon . l($d['nick'], 'guifi/device/' . $d['id'], array('attributes' => array('target' => '_blank'))), array('data' => l($ip['ipv4'] . '/' . $ip['maskbits'], guifi_device_admin_url($d, $ip['ipv4']), array('attributes' => array('title' => t('Connect to the device on a new window'), 'target' => '_blank'))), 'align' => 'right'), array('data' => $edit_ok_icon, 'class' => $d['flag']), array('data' => $status_url, 'class' => $d['flag'])); } return $rows; } global $user; $owner = $user->uid; guifi_log(GUIFILOG_TRACE, 'function guifi_users_node_list()', $zone); drupal_set_breadcrumb(guifi_zone_ariadna($zone->id, 'node/%d/view/userqueue')); $title = t('Queue of pending users @') . ' ' . $zone->title; drupal_set_title($title); $childs = guifi_zone_childs($zone->id); $childs[] = $zone->id; $sql = 'SELECT ' . ' u.*, l.id nid, l.nick nnick, l.status_flag nflag, l.zone_id ' . 'FROM {guifi_users} u, {guifi_location} l ' . 'WHERE u.nid=l.id' . ' AND (l.status_flag != "Working" OR u.status != "Approved") ' . ' AND l.zone_id IN (' . implode(',', $childs) . ') ' . 'ORDER BY FIND_IN_SET(u.status,"New,Pending,Approved,Rejected"),' . ' u.timestamp_created'; $query = pager_query($sql, variable_get("guifi_pagelimit", 50)); $rows = array(); $nrow = 0; if (user_access('administer guifi networks') || user_access('administer guifi zones') || user_access('administer guifi users')) { $administer = TRUE; } else { $administer = FALSE; } while ($u = db_fetch_array($query)) { $pUser = (object) guifi_user_load($u['id']); $proxy = node_load(array('nid' => $pUser->services['proxy'])); $srows = _guifi_user_queue_devices($u); $nsr = count($srows); if (empty($nsr)) { $nsr = 1; } $node = node_load(array('nid' => $u['nid'])); if (guifi_node_access('update', $node)) { $edit_node_icon = l(guifi_img_icon('edit.png'), 'node/' . $u['nid'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'node/' . $u['nid'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank'))); } else { $edit_node_icon = ''; } if (guifi_user_access('update', $u)) { $edit_user_icon = l(guifi_img_icon('edit.png'), 'guifi/user/' . $u['id'] . '/edit', array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . l(guifi_img_icon('drop.png'), 'guifi/user/' . $u['id'] . '/delete', array('html' => TRUE, 'attributes' => array('target' => '_blank'))); } else { $edit_user_icon = ''; } if ($administer) { $edit_user_form = drupal_get_form('_guifi_user_queue_form', $u); } else { $edit_user_form = $u['status']; } if (user_access('administer guifi users') or $node->uid == $owner) { $rn3 = $u['lastname'] . ", " . $u['firstname']; $u3 = $u['username']; } else { $rn3 = ereg_replace("_", " ", $u['lastname'] . ", " . $u['firstname']); if (strlen($rn3) > 3) { $rn3 = substr($u['lastname'] . ", " . $u['firstname'], 0, 3); $rn3 .= ".."; } $u3 = $u['username']; if (strlen($u3) > 3) { $u3 = substr($u['username'], 0, 5); $u3 .= ".."; } } $rows[] = array(array('data' => $edit_user_icon . l($u3, 'node/' . $u['nid'] . '/view/users', array('attributes' => array('title' => $rn3, 'target' => '_blank'))) . "\n<br />" . '<small>' . format_date($u['timestamp_created']) . '<br />' . l($proxy->nick, "node/" . $proxy->id, array('attributes' => array('title' => $proxy->title))), 'rowspan' => $nsr), array('data' => guifi_get_zone_nick($u['zone_id']) . "<br /><strong>" . $edit_node_icon . l($u['nnick'], 'node/' . $u['nid'], array('html' => TRUE, 'attributes' => array('target' => '_blank'))) . '</strong><br /><small>' . l(t('add a comment'), 'comment/reply/' . $u['nid'], array('fragment' => 'comment-form', 'html' => TRUE, 'attributes' => array('title' => t('Add a comment to the page of this node'), 'target' => '_blank'))) . '</small>', 'class' => $u['nflag'], 'rowspan' => $nsr), array('data' => $edit_user_form, 'rowspan' => $nsr)); end($rows); $krow = key($rows); if (count($srows)) { // merge current row with first element $rows[$krow] = array_merge($rows[$krow], array_shift($srows)); // adding rest og the elements foreach ($srows as $k => $v) { $rows[] = $v; } } } $header = array(t('Username'), t('Node'), t('User status'), t('Device'), t('IP v4 address'), t('Status & MAC'), t('Current status')); $output .= theme('table', $header, $rows); $output .= theme_pager(NULL, variable_get("guifi_pagelimit", 50)); // Full screen (no lateral bars, etc...) print theme('page', $output, FALSE); // If normal output, retrurn $output... }