From 969bf73275f5759faf02b46426aa7b084f598a17 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Fri, 27 Jan 2006 20:35:55 +0000 Subject: [PATCH] Disabling certain form features to prep for Beta 1. Added better error handling Bugfixes git-svn-id: https://svn.alkaloid.net/gpl/shout/trunk@270 06cd67b6-e706-0410-b29e-9de616bca6e9 --- andrew.session | 78 ++++++++++++++++---------------- andrew.webprj | 78 ++++++++++++++++---------------- lib/User.php | 84 ++++++++++++++++++---------------- templates/users/userlist.inc | 2 +- usermgr/edit.php | 104 ++++++++++++++++++++++--------------------- usermgr/save.php | 81 ++++++++++++++++++--------------- 6 files changed, 222 insertions(+), 205 deletions(-) diff --git a/andrew.session b/andrew.session index 20026bd22..409850ca3 100644 --- a/andrew.session +++ b/andrew.session @@ -60,62 +60,62 @@ - - - + + + - - + + - - + + - - - - - - + + + + + + - + - + - - + + - - + + - + - + - - - - + + + + - - - - + + + + - + - - - - + + + + - - - - + + + + @@ -129,14 +129,12 @@ - - diff --git a/andrew.webprj b/andrew.webprj index 67f531a5a..590f5699a 100644 --- a/andrew.webprj +++ b/andrew.webprj @@ -1,45 +1,45 @@ - + -//w3c//dtd xhtml 1.0 strict//en - + - + - - - - - - - + + + + + + + - + - + - - - - + + + + - - - - - - + + + + + + - - - - - + + + + + @@ -102,11 +102,11 @@ templates/ toolbars/ - - + + - - + + @@ -129,14 +129,14 @@ - - - - + + + + - - - - + + + + diff --git a/lib/User.php b/lib/User.php index 3085ae37c..2b7f48310 100644 --- a/lib/User.php +++ b/lib/User.php @@ -15,30 +15,36 @@ class UserDetailsForm extends Horde_Form { function UserDetailsForm(&$vars) { - global $shout; - $context = $vars->get("context"); - $extension = $vars->get("extension"); + global $shout, $notification; + $context = $vars->get('context'); + $curexten = $vars->get('curexten'); $users = &$shout->getUsers($context); - if (array_key_exists($extension, $users)) { + if (is_a($users, 'PEAR_Error')) { + $notification->push($users); + } + if (array_key_exists($curexten, $users)) { # We must be editing an existing user - $this->fillUserForm(&$vars, $users[$extension]); - $limits = &$shout->getLimits($context, $extension); + $this->fillUserForm(&$vars, $users[$curexten]); + $limits = &$shout->getLimits($context, $curexten); + if (is_a($limits, 'PEAR_Error')) { + $notification->push($limits); + } $formtitle = "Edit User"; } else { $limits = &$shout->getLimits($context); + if (is_a($limits, 'PEAR_Error')) { + $notification->push($limits); + } $formtitle = "Add User"; } parent::Horde_Form($vars, _("$formtitle - Context: $context")); - $this->addHidden('', 'context', 'text', true); - $this->addHidden('', 'curextension', 'text', true); - $vars->set('curextension', $extension); $this->addHidden('', 'action', 'text', true); - $vars->set('action', 'edit'); + $vars->set('action', 'save'); $this->addVariable(_("Full Name"), 'name', 'text', true); - $this->addVariable(_("Extension"), 'newextension', 'int', true); + $this->addVariable(_("Extension"), 'newexten', 'int', true); $this->addVariable(_("E-Mail Address"), 'email', 'text', true); $this->addVariable(_("Pager E-Mail Address"), 'pageremail', 'text', false); # TODO: Integrate with To-Be-Written user manager and possibly make this @@ -59,14 +65,14 @@ class UserDetailsForm extends Horde_Form { 'boolean', true, false);#, _("When checked, the called user will be allowed to transfer the incoming call to other extensions")); $this->addVariable(_("Explicit Call Acceptance"), 'eca', 'boolean', true, false);#, _("When checked, the called user will be required to press 1 to accept the call. Only turn this off if you really know what you're doing!")); - $this->addVariable(_("Call Appearance"), 'callappearance', - 'radio', $vars->get('eca'), false, null, array('values' => - array('caller' => 'From Calling Party', - 'self' => 'From Self', - 'switch' => 'From V-Office', - ) - ) - ); +// $this->addVariable(_("Call Appearance"), 'callappearance', +// 'radio', $vars->get('eca'), false, null, array('values' => +// array('caller' => 'From Calling Party', +// 'self' => 'From Self', +// 'switch' => 'From V-Office', +// ) +// ) +// ); return true; } @@ -89,7 +95,7 @@ class UserDetailsForm extends Horde_Form { $vars->set('name', $userdetails['name']); $vars->set('email', @$userdetails['email']); $vars->set('pin', $userdetails['mailboxpin']); - $vars->set('newextension', $vars->get('extension')); + $vars->set('newexten', $vars->get('curexten')); $i = 1; foreach($userdetails['phonenumbers'] as $number) { @@ -100,7 +106,7 @@ class UserDetailsForm extends Horde_Form { $vars->set('moh', false); $vars->set('eca', false); $vars->set('transfer', false); - $vars->set('callappearance', 'caller'); +// $vars->set('callappearance', 'caller'); foreach ($userdetails['dialopts'] as $opt) { @@ -113,24 +119,24 @@ class UserDetailsForm extends Horde_Form { if (preg_match('/^e(\(.*\))*/', $opt, $matches)) { # This matches 'e' and 'e(ARGS)' $vars->set('eca', true); - if (count($matches) > 1) { - # We must have found an argument - switch($matches[1]) { - case '(${VOFFICENUM})': - $vars->set('callappearance', 'switch'); - break; - - case '(${CALLERANI})': - $vars->set('callappearance', 'self'); - break; - - case '(${CALLERIDNUM})': - default: - $vars->set('callappearance', 'caller'); - break; - - } - } +// if (count($matches) > 1) { +// # We must have found an argument +// switch($matches[1]) { +// case '(${VOFFICENUM})': +// $vars->set('callappearance', 'switch'); +// break; +// +// case '(${CALLERANI})': +// $vars->set('callappearance', 'self'); +// break; +// +// case '(${CALLERIDNUM})': +// default: +// $vars->set('callappearance', 'caller'); +// break; +// +// } +// } } } return true; diff --git a/templates/users/userlist.inc b/templates/users/userlist.inc index 79881f522..67c671813 100644 --- a/templates/users/userlist.inc +++ b/templates/users/userlist.inc @@ -18,7 +18,7 @@ $url = Util::addParameter($url, array( 'context' => $context, - 'extension' => $extension, + 'curexten' => $extension, 'section' => 'users', ) ); diff --git a/usermgr/edit.php b/usermgr/edit.php index d069872ee..988d9b29b 100644 --- a/usermgr/edit.php +++ b/usermgr/edit.php @@ -9,8 +9,11 @@ * * @package shout */ -@define('SHOUT_BASE', dirname(__FILE__) . '/..'); -require_once SHOUT_BASE . '/lib/base.php'; +if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { + header('Location: /'); + exit(); +} + require_once SHOUT_BASE . '/lib/User.php'; require_once 'Horde/Variables.php'; @@ -21,26 +24,24 @@ $beendone = 0; $wereerrors = 0; $vars = &Variables::getDefaultVariables($empty); -$formname = $vars->get('formname'); - -$Form = &Horde_Form::singleton('UserDetailsForm', $vars); -$FormValid = $Form->validate($vars, true); - -if ($Form->isSubmitted()) { - $notification->push('Submitted.', 'horde.message'); -} -if ($FormValid) { - $notification->push('Valid.', 'horde.message'); +$FormName = 'UserDetailsForm'; +$Form = &Horde_Form::singleton($FormName, $vars); +if (is_a($Form, 'PEAR_Error')) { + $notification->push($Form); +} else { + $FormValid = $Form->validate($vars, true); + if (is_a($FormValid, 'PEAR_Error')) { + $notification->push($FormValid); + } } + $notification->notify(); if (!$FormValid || !$Form->isSubmitted()) { # Display the form for editing - $Form->open($RENDERER, $vars, 'usermgr.php', 'post'); - $vars->set('section', $section); - $Form->preserveVarByPost($vars, "section"); - // $Form->preserve($vars); + $Form->open($RENDERER, $vars, 'index.php', 'post'); + $Form->preserve($vars); $RENDERER->beginActive($Form->getTitle()); $RENDERER->renderFormActive($Form, $vars); $RENDERER->submit(); @@ -48,39 +49,40 @@ if (!$FormValid || !$Form->isSubmitted()) { $Form->close($RENDERER); } else { # Process the Valid and Submitted form - - $info = array(); - $Form->getInfo($vars, $info); - - $name = $info['name']; - $curextension = $info['curextension']; - $newextension = $info['newextension']; - $email = $info['email']; - $pin = $info['pin']; - - - $limits = $shout->getLimits($context, $curextension); - - $userdetails = array("newextension" => $newextension, - "name" => $name, - "pin" => $pin, - "email" => $email); - - $i = 1; - $userdetails['telephonenumbers'] = array(); - while ($i <= $limits['telephonenumbersmax']) { - $tmp = $info['telephone'.$i]; - if (!empty($tmp)) { - $userdetails['telephonenumbers'][] = $tmp; - } - $i++; - } - - $userdetails['dialopts'] = array(); - if ($info['moh']) { - $userdetails['dialopts'][] = 'm'; - } - if ($info['transfer']) { - $userdetails['dialopts'][] = 't'; - } +$notification->push("How did we get HERE?!", 'horde.error'); +$notification->notify(); +// $info = array(); +// $Form->getInfo($vars, $info); +// +// $name = $info['name']; +// $curextension = $info['curextension']; +// $newextension = $info['newextension']; +// $email = $info['email']; +// $pin = $info['pin']; +// +// +// $limits = $shout->getLimits($context, $curextension); +// +// $userdetails = array("newextension" => $newextension, +// "name" => $name, +// "pin" => $pin, +// "email" => $email); +// +// $i = 1; +// $userdetails['telephonenumbers'] = array(); +// while ($i <= $limits['telephonenumbersmax']) { +// $tmp = $info['telephone'.$i]; +// if (!empty($tmp)) { +// $userdetails['telephonenumbers'][] = $tmp; +// } +// $i++; +// } +// +// $userdetails['dialopts'] = array(); +// if ($info['moh']) { +// $userdetails['dialopts'][] = 'm'; +// } +// if ($info['transfer']) { +// $userdetails['dialopts'][] = 't'; +// } } \ No newline at end of file diff --git a/usermgr/save.php b/usermgr/save.php index 7ebe3873f..bcc379a80 100644 --- a/usermgr/save.php +++ b/usermgr/save.php @@ -9,55 +9,66 @@ * * @package shout */ -@define('SHOUT_BASE', dirname(__FILE__) . '/..'); +if (!isset($SHOUT_RUNNING) || !$SHOUT_RUNNING) { + header('Location: /'); + exit(); +} + require_once SHOUT_BASE . '/lib/User.php'; require_once 'Horde/Variables.php'; $RENDERER = &new Horde_Form_Renderer(); $vars = &Variables::getDefaultVariables(); -$formname = $vars->get('formname'); +$FormName = $vars->get('formname'); -$UserDetailsForm = &Horde_Form::singleton('UserDetailsForm', $vars); -$UserDetailsFormValid = $UserDetailsForm->validate($vars, true); -if (!$UserDetailsFormValid) { - # FIXME Handle invalid forms gracefully - echo "Invalid Form!"; -} +$Form = &Horde_Form::singleton($FormName, $vars); -$name = Util::getFormData('name'); -$curextension = Util::getFormData('curextension'); -$newextension = Util::getFormData('newextension'); -$email = Util::getFormData('email'); -$pin = Util::getFormData('pin'); +$FormValid = $Form->validate($vars, true); +if (!$FormValid || !$Form->isSubmitted()) { + require SHOUT_BASE . '/usermgr/edit.php'; +} else { + # Form is Valid and Submitted + $name = $vars->get('name'); + $curexten = $vars->get('curexten'); + $newexten = $vars->get('newexten'); + $email = $vars->get('email'); + $pin = $vars->get('pin'); -$limits = $shout->getLimits($context, $curextension); -$userdetails = array("newextension" => $newextension, - "name" => $name, - "pin" => $pin, - "email" => $email); + $limits = $shout->getLimits($context, $curexten); -$i = 1; -$userdetails['telephonenumbers'] = array(); -while ($i <= $limits['telephonenumbersmax']) { - $tmp = Util::getFormData("telephone$i"); - if (!empty($tmp)) { - $userdetails['telephonenumbers'][] = $tmp; + $userdetails = array("newexten" => $newexten, + "name" => $name, + "pin" => $pin, + "email" => $email); + + $i = 1; + $userdetails['telephonenumbers'] = array(); + while ($i <= $limits['telephonenumbersmax']) { + $tmp = $vars->get("telephone$i"); + $notification->push('Number: '.$tmp, 'horde.warning'); + if (!empty($tmp)) { + $userdetails['telephonenumbers'][] = $tmp; + } + $i++; } - $i++; -} -$userdetails['dialopts'] = array(); -if (Util::getFormData('moh')) { - $userdetails['dialopts'][] = 'm'; -} -if (Util::getFormData('transfer')) { - $userdetails['dialopts'][] = 't'; + $userdetails['dialopts'] = array(); + if ($vars->get('moh')) { + $userdetails['dialopts'][] = 'm'; + } + if ($vars->get('transfer')) { + $userdetails['dialopts'][] = 't'; + } + if ($vars->get('eca')) { + $userdetails['dialopts'][] = 'e'; + } + $notification->notify(); + print_r($userdetails); } - -// $res = $shout->saveUser($context, $curextension, $userdetails); +// $res = $shout->saveUser($context, $curexten, $userdetails); // if (is_a($res, 'PEAR_Error')) { -// print $res->getMessage(); +// $notification->push($res); // } \ No newline at end of file -- 2.11.0