class Toolkit_Contacts_Admin_EditContact
extends Toolkit_FormBuilder implements Toolkit_Form
{
- // {{{ properties
+ // {{{ properties
/**
* Table in Database which holds the contact data
- *
+ *
* @var string
* @access public
*/
- public $tableName = 'contact';
+ public $tableName = 'contact';
/**
* Primary Key for the table
- *
+ *
* @var string
* @access public
*/
/**
* Sequence for the table
- *
+ *
* @var string
* @access public
*/
/**
* Table meta data
- *
- * This is used when inserting/updating data for the records
- * so the PDO's can use explicit data types for the parameters.
- *
+ *
+ * This is used when inserting/updating data for the records
+ * so the PDO's can use explicit data types for the parameters.
+ *
* @var array
* @access public
*/
- public $tableMetaData = array();
+ public $tableMetaData = array();
/**
* The interests from the contact db
- *
+ *
* @var array
* @access protected
*/
- protected $inquiries = array();
-
- /**
- * What do you want the error msg to be if the form doesn't validate
- *
- * @var string
- * @access protected
- */
- protected $errorMsg
+ protected $inquiries = array();
+
+ /**
+ * What do you want the error msg to be if the form doesn't validate
+ *
+ * @var string
+ * @access protected
+ */
+ protected $errorMsg
= '<div id="form-warning-top">
Warning: The form was not sent, please review the errors below.
</div>';
- /**
- * What do you want the success msg to be if the form validates successfully
- *
- * @var string
- * @access protected
- */
- protected $successMsg
+ /**
+ * What do you want the success msg to be if the form validates successfully
+ *
+ * @var string
+ * @access protected
+ */
+ protected $successMsg
= '<div id="form-success-top">
The information below has been successfully submitted.
</div>';
/**
* Include a captcha on the form or not
- *
+ *
* @var boolean
* @access protected
*/
- protected $useCaptcha = false;
-
- /**
- * The default templates to inject into the form renderer
- *
- * @var string
- * @access protected
- */
- protected $template;
-
- /**
- * The default rules to register for validating
- *
- * We have to register these rules, or any others we want, before
- * we are able to use them in our forms.
- *
- * These rules can be removed in subclasses before the rules are configured
- * if you want to omit any of them from validating input - just remember
- * to not call them in your configured rules!
- *
- * Phone: validates input against US and CA style phone #'s
- * <code>
- * $rules[] = array('element' => 'phone',
- * 'message' => 'ERROR: Invalid Phone Format!',
- * 'type' => 'phone',
- * 'format' => null,
- * 'validation' => $this->validationType,
- * 'reset' => true,
- * 'force' => false);
- * </code>
- *
- * Zip: Validates input against US and CA zip codes, if DB check is
- * set to true, validate zip codes against all the zip codes in the
- * DB.
- * <code>
- * $rules[] = array('element' => 'zip',
- * 'message' => 'ERROR: Invalid Zip!',
- * 'type' => 'zip',
- * 'format' => array('requireDBCheck' => true),
- * 'validation' => $this->validationType,
- * 'reset' => true,
- * 'force' => false);
- * </code>
- *
- * Banwords: Make sure each each doesn't contain a banned word. Checking
- * against a DB of banned words.
- *
- * State: Validate input against US and CA region / province codes. If DB
- * check is set to true, validate region / province against all the
- * regions / provinces in the DB.
- * <code>
- * $rules[] = array('element' => 'state_id',
- * 'message' => 'ERROR: Invalid State / Province!',
- * 'type' => 'state',
- * 'format' => array('requireDBCheck' => true),
- * 'validation' => $this->validationType,
- * 'reset' => true,
- * 'force' => false);
- * </code>
- *
- * @var array
- * @access protected
- * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/Zip.php
- * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/Phone.php
- * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/Banwords.php
- * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/State.php
- */
- protected $registeredRules = array('phone', 'zip', 'state');
-
- // }}}
- // {{{ __construct()
-
- /**
- * Class constructor
- *
+ protected $useCaptcha = false;
+
+ /**
+ * The default templates to inject into the form renderer
+ *
+ * @var string
+ * @access protected
+ */
+ protected $template;
+
+ /**
+ * The default rules to register for validating
+ *
+ * We have to register these rules, or any others we want, before
+ * we are able to use them in our forms.
+ *
+ * These rules can be removed in subclasses before the rules are configured
+ * if you want to omit any of them from validating input - just remember
+ * to not call them in your configured rules!
+ *
+ * Phone: validates input against US and CA style phone #'s
+ * <code>
+ * $rules[] = array('element' => 'phone',
+ * 'message' => 'ERROR: Invalid Phone Format!',
+ * 'type' => 'phone',
+ * 'format' => null,
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ * </code>
+ *
+ * Zip: Validates input against US and CA zip codes, if DB check is
+ * set to true, validate zip codes against all the zip codes in the
+ * DB.
+ * <code>
+ * $rules[] = array('element' => 'zip',
+ * 'message' => 'ERROR: Invalid Zip!',
+ * 'type' => 'zip',
+ * 'format' => array('requireDBCheck' => true),
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ * </code>
+ *
+ * Banwords: Make sure each each doesn't contain a banned word. Checking
+ * against a DB of banned words.
+ *
+ * State: Validate input against US and CA region / province codes. If DB
+ * check is set to true, validate region / province against all the
+ * regions / provinces in the DB.
+ * <code>
+ * $rules[] = array('element' => 'state_id',
+ * 'message' => 'ERROR: Invalid State / Province!',
+ * 'type' => 'state',
+ * 'format' => array('requireDBCheck' => true),
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ * </code>
+ *
+ * @var array
+ * @access protected
+ * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/Zip.php
+ * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/Phone.php
+ * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/Banwords.php
+ * @see app.gaslightmedia.com/glmPEAR/HTML/QuickForm/Rule/State.php
+ */
+ protected $registeredRules = array('phone', 'zip', 'state');
+
+ // }}}
+ // {{{ __construct()
+
+ /**
+ * Class constructor
+ *
* @param object $pdo PHP Data Object
* @param string $formName Form's name.
* @param string $method (optional)Form's method defaults to 'POST'
* @param string $target (optional)Form's target defaults to '_self'
* @param mixed $attributes (optional)Extra attributes for <form> tag
* @param bool $trackSubmit (optional)Whether to track if the form was
- * submitted by adding a special hidden field
- *
- * @author Jamie Kahgee <jamie.kahgee@gmail.com>
- * @access public
- * @link http://pear.php.net/package/HTML_QuickForm/docs/latest/HTML_QuickForm/HTML_QuickForm.html
- * @see HTML_QuickForm
- */
- public function __construct(
+ * submitted by adding a special hidden field
+ *
+ * @author Jamie Kahgee <jamie.kahgee@gmail.com>
+ * @access public
+ * @link http://pear.php.net/package/HTML_QuickForm/docs/latest/HTML_QuickForm/HTML_QuickForm.html
+ * @see HTML_QuickForm
+ */
+ public function __construct(
PDO $pdo,
$formName,
$method = 'post',
$attributes = null,
$trackSubmit = false
) {
- parent::__construct(
+ parent::__construct(
$formName,
$method,
$action,
$this->dbh = $pdo;
- /**
- * Where are the flexy templates stored at for this class.
- */
- define('TEMPLATES_DIR', BASE . 'Toolkit/Contacts/templates');
-
- /**
- * Where are the compiled flexy templates stored at for this class.
- */
- define('COMPILED_DIR', BASE . 'Toolkit/Contacts/templates/compiled');
- $oldUmask = umask(0);
- if (!is_dir(TEMPLATES_DIR)) {
- mkdir(TEMPLATES_DIR, 0770, true);
- }
- if (!is_dir(COMPILED_DIR)) {
- mkdir(COMPILED_DIR, 0770, true);
- }
- umask($oldUmask);
-
- $this->flexyOptions = $GLOBALS['flexyOptions'];
- $this->flexyOptions['templateDir'] = TEMPLATES_DIR;
- $this->flexyOptions['compileDir'] = COMPILED_DIR;
-
- }
-
- // }}}
-
- // {{{ checkContactEmail()
-
- /**
- * Checks if the member name already exists in the database
- *
- * @param array $data The name of the member to check for.
+ /**
+ * Where are the flexy templates stored at for this class.
+ */
+ define('TEMPLATES_DIR', BASE . 'Toolkit/Contacts/templates');
+
+ /**
+ * Where are the compiled flexy templates stored at for this class.
+ */
+ define('COMPILED_DIR', BASE . 'Toolkit/Contacts/templates/compiled');
+ $oldUmask = umask(0);
+ if (!is_dir(TEMPLATES_DIR)) {
+ mkdir(TEMPLATES_DIR, 0770, true);
+ }
+ if (!is_dir(COMPILED_DIR)) {
+ mkdir(COMPILED_DIR, 0770, true);
+ }
+ umask($oldUmask);
+
+ $this->flexyOptions = $GLOBALS['flexyOptions'];
+ $this->flexyOptions['templateDir'] = TEMPLATES_DIR;
+ $this->flexyOptions['compileDir'] = COMPILED_DIR;
+
+ }
+
+ // }}}
+
+ // {{{ checkContactEmail()
+
+ /**
+ * Checks if the member name already exists in the database
*
- * @return bool False on SQL Query error, otherwise true.
- * @access protected
- */
- public function checkContactEmail($data)
- {
- try {
- // If we're editing a contact, they
- // can save that member as its
- // own name. so don't include that
- // member in the check.
- if (ctype_digit($_REQUEST[$this->primaryKey])) {
- $and = "AND {$this->primaryKey} <> :id";
- }
- $sql = "
- SELECT count(*) AS total
- FROM {$this->tableName}
- WHERE email = :email
- $and";
- $stmt = $this->dbh->prepare($sql);
- $stmt->bindParam(':email', $data, PDO::PARAM_STR);
- if (ctype_digit($_REQUEST[$this->primaryKey])) {
- $stmt->bindParam(':id', $_REQUEST[$this->primaryKey], PDO::PARAM_STR);
- }
- $stmt->execute();
+ * @param array $data The name of the member to check for.
+ *
+ * @return bool False on SQL Query error, otherwise true.
+ * @access protected
+ */
+ public function checkContactEmail($data)
+ {
+ try {
+ // If we're editing a contact, they
+ // can save that member as its
+ // own name. so don't include that
+ // member in the check.
+ if (ctype_digit($_REQUEST[$this->primaryKey])) {
+ $and = "AND {$this->primaryKey} <> :id";
+ }
+ $sql = "
+ SELECT count(*) AS total
+ FROM {$this->tableName}
+ WHERE email = :email
+ $and";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':email', $data, PDO::PARAM_STR);
+ if (ctype_digit($_REQUEST[$this->primaryKey])) {
+ $stmt->bindParam(':id', $_REQUEST[$this->primaryKey], PDO::PARAM_STR);
+ }
+ $stmt->execute();
$stmt->bindColumn('total', $valid);
- $stmt->fetch();
+ $stmt->fetch();
- return !(bool) $valid;
- } catch (PDOException $e) {
- return Toolkit_Common::handleError($e);
- }
- }
+ return !(bool) $valid;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
- // }}}
- // {{{ configureConstats()
+ // }}}
+ // {{{ configureConstats()
/**
* Constant variables for the form
- *
- * These values won't get overridden by POST or GET vars
+ *
+ * These values won't get overridden by POST or GET vars
*
* @return void
* @access public
*/
- public function configureConstants()
- {
+ public function configureConstants()
+ {
if (ctype_digit($_REQUEST['id'])) {
- $constants = array('id' => $_REQUEST['id']);
+ $constants = array('id' => $_REQUEST['id']);
} else {
- $constants = array();
+ $constants = array();
}
- $this->setupConstants($constants);
- }
+ $this->setupConstants($constants);
+ }
- // }}}
- // {{{ configureDefaults()
+ // }}}
+ // {{{ configureDefaults()
/**
* Initializes default form values
* @return void
* @access public
*/
- public function configureDefaults()
- {
+ public function configureDefaults()
+ {
if (ctype_digit($_REQUEST[$this->primaryKey])) {
try {
$sql = "
);
}
- $this->setupDefaults($defaults);
- }
+ $this->setupDefaults($defaults);
+ }
- // }}}
- // {{{ configureElements()
+ // }}}
+ // {{{ configureElements()
/**
* Form element definitions
* @return void
* @access public
*/
- public function configureElements()
- {
- $e = array();
- $this->setInterestFields();
- // Grouped Elements are defined here.
- $this->interestsGroups =& $this->getInterestFields();
+ public function configureElements()
+ {
+ $e = array();
+ $this->setInterestFields();
+ // Grouped Elements are defined here.
+ $this->interestsGroups =& $this->getInterestFields();
$contactTypesSetup
= $this->config->getItem('section', 'contact_types')
->toArray();
$cType = $contactTypesSetup['contact_types'];
- // All Elements are created here. This includes group element definitions.
+ // All Elements are created here. This includes group element definitions.
$e[] = array(
'type' => 'hidden',
'name' => 'start',
'display' => $_REQUEST['start']
);
- $e[] = array(
- 'type' => 'static',
- 'req' => false,
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
'name' => 'user_agent',
'display' => 'User Agent'
- );
- $e[] = array(
- 'type' => 'static',
- 'req' => false,
- 'name' => 'remote_addr',
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'remote_addr',
'display' => 'Remote Address'
- );
+ );
if (ctype_digit($_REQUEST[$this->primaryKey])) {
$e[] = array(
'type' => 'hidden',
'name' => $this->primaryKey
);
}
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => 'fname',
- 'display' => 'First Name'
- );
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => 'lname',
- 'display' => 'Last Name'
- );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'fname',
+ 'display' => 'First Name'
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'lname',
+ 'display' => 'Last Name'
+ );
if ($this->tableName == 'customer') {
$add1 = 'add1';
$add2 = 'add2';
$add1 = 'address';
$add2 = 'address2';
}
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => $add1,
- 'display' => 'Address 1'
- );
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => $add2,
- 'display' => 'Address 2'
- );
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => 'city',
- 'display' => 'City'
- );
$e[] = array(
- 'type' => 'select',
- 'req' => false,
- 'name' => 'state',
- 'display' => 'State/Province',
- 'opts' => $GLOBALS['states']
- );
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => $add1,
+ 'display' => 'Address 1'
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => $add2,
+ 'display' => 'Address 2'
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'city',
+ 'display' => 'City'
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'state',
+ 'display' => 'State/Province',
+ 'opts' => $GLOBALS['states']
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'zip',
+ 'display' => 'ZIP/Postal Code'
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'email',
+ 'display' => 'Email'
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'phone',
+ 'display' => 'Phone'
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'fax',
+ 'display' => 'Fax'
+ );
$e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => 'zip',
- 'display' => 'ZIP/Postal Code'
- );
- $e[] = array(
- 'type' => 'text',
- 'req' => true,
- 'name' => 'email',
- 'display' => 'Email'
- );
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => 'phone',
- 'display' => 'Phone'
- );
- $e[] = array(
- 'type' => 'text',
- 'req' => false,
- 'name' => 'fax',
- 'display' => 'Fax'
- );
- $e[] = array(
- 'type' => 'advcheckbox',
- 'req' => false,
- 'name' => 'mail_ok',
- 'display' => 'Mail Ok?',
- 'opts' => 'Yes',
- 'val' => array(0, 1)
- );
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'mail_ok',
+ 'display' => 'Mail Ok?',
+ 'opts' => 'Yes',
+ 'val' => array(0, 1)
+ );
if (is_array($this->interestsGroups)) {
foreach ($this->interestsGroups as $group => $gData) {
$this->myGroups[] = $gData;
'type' => 'group',
'req' => false,
'name' => 'interest['.$group.']',
- 'group' => $gData,
+ 'group' => $gData,
'label' => $group,
'seperator' => ' ',
'appendName' => true
'opts' => $cType,
'att' => array('multiple' => 'multiple')
);
- $e[] = array(
- 'type' => 'submit',
- 'req' => false,
- 'name' => 'submit_rmv',
+ $e[] = array(
+ 'type' => 'submit',
+ 'req' => false,
+ 'name' => 'submit_rmv',
'display' => 'Submit Form'
- );
+ );
- $this->setupElements($e);
- }
+ $this->setupElements($e);
+ }
- // }}}
- // {{{ configureRules()
+ // }}}
+ // {{{ configureRules()
/**
* Form rule definitions
*
- * Adds validation rules for the given fields
+ * Adds validation rules for the given fields
*
* @return void
* @access public
*/
- public function configureRules()
- {
- $r = array();
- // Form Rules
- $r[] = array(
- 'element' => 'email',
- 'message' => 'ERROR: Invalid Email Format!',
- 'type' => 'email',
- 'format' => array('use_rfc822' => true),
- 'validation' => $this->validationType,
- 'reset' => true,
- 'force' => false
+ public function configureRules()
+ {
+ $r = array();
+ // Form Rules
+ $r[] = array(
+ 'element' => 'email',
+ 'message' => 'ERROR: Invalid Email Format!',
+ 'type' => 'email',
+ 'format' => array('use_rfc822' => true),
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
);
- $r[] = array(
- 'element' => 'phone',
- 'message' => 'ERROR: Invalid number (xxx) xxx-xxxx!',
- 'type' => 'phone',
- 'format' => null,
- 'validation' => $this->validationType,
- 'reset' => true,
- 'force' => false
+ $r[] = array(
+ 'element' => 'phone',
+ 'message' => 'ERROR: Invalid number (xxx) xxx-xxxx!',
+ 'type' => 'phone',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
);
- $r[] = array(
- 'element' => 'fax',
- 'message' => 'ERROR: Invalid number (xxx) xxx-xxxx!',
- 'type' => 'phone',
- 'format' => null,
- 'validation' => $this->validationType,
- 'reset' => true,
- 'force' => false
+ $r[] = array(
+ 'element' => 'fax',
+ 'message' => 'ERROR: Invalid number (xxx) xxx-xxxx!',
+ 'type' => 'phone',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
);
- $r[] = array(
- 'element' => 'zip',
- 'message' => 'ERROR: Invalid Zip!',
- 'type' => 'zip',
- 'format' => array('requireDBCheck' => false),
- 'validation' => $this->validationType,
- 'reset' => true,
- 'force' => false
+ $r[] = array(
+ 'element' => 'zip',
+ 'message' => 'ERROR: Invalid Zip!',
+ 'type' => 'zip',
+ 'format' => array('requireDBCheck' => false),
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
);
- $r[] = array(
- 'element' => 'mail_ok',
- 'message' => 'ERROR: Invalid Value!',
- 'type' => 'numeric',
- 'format' => null,
- 'validation' => $this->validationType,
- 'reset' => true,
- 'force' => false
+ $r[] = array(
+ 'element' => 'mail_ok',
+ 'message' => 'ERROR: Invalid Value!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
);
- $r[] = array(
- 'element' => 'email',
- 'message' => 'ERROR: There is an existing account with this name!',
- 'type' => 'callback',
- 'format' => array($this, 'checkContactEmail'),
- 'validation' => $this->validationType,
- 'reset' => false,
- 'force' => false
- );
-
- $this->setupRules($r);
- }
-
- // }}}
- // {{{ configureFilters()
+ $r[] = array(
+ 'element' => 'email',
+ 'message' => 'ERROR: There is an existing account with this name!',
+ 'type' => 'callback',
+ 'format' => array($this, 'checkContactEmail'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+
+ $this->setupRules($r);
+ }
+
+ // }}}
+ // {{{ configureFilters()
/**
* Form filter definitions
*
- * Applies a data filter for the given fields when the form is submitted
+ * Applies a data filter for the given fields when the form is submitted
*
* @return void
* @access public
*/
- public function configureFilters()
- {
+ public function configureFilters()
+ {
$f = array();
- $f[] = array(
+ $f[] = array(
'element' => '__ALL__',
'filter' => 'trim'
);
$this->setupFilters($f);
- }
+ }
- // }}}
+ // }}}
// {{{ configureForm()
/**
*/
protected function contactExists($email)
{
- // Check if a contact w/ the submitted email already exists.
- // if so, then we need to update, if not then do a fresh insert.
- try {
- $sql = "
- SELECT count(*) AS count
- FROM {$this->tableName}
- WHERE email = :email";
-
- $stmt = $this->dbh->prepare($sql);
- $stmt->bindParam(':email', $email, PDO::PARAM_STR);
- $stmt->execute();
- $stmt->bindColumn('count', $contactExists);
- $stmt->fetch();
+ // Check if a contact w/ the submitted email already exists.
+ // if so, then we need to update, if not then do a fresh insert.
+ try {
+ $sql = "
+ SELECT count(*) AS count
+ FROM {$this->tableName}
+ WHERE email = :email";
+
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':email', $email, PDO::PARAM_STR);
+ $stmt->execute();
+ $stmt->bindColumn('count', $contactExists);
+ $stmt->fetch();
return (bool) $contactExists;
- } catch (PDOException $e) {
- return Toolkit_Common::handleError($e);
- }
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
}
// }}}
- // {{{ error()
+ // {{{ error()
/**
* Display errors with the form to the user
*
* @param object $error PEAR Error Object
- *
+ *
* @return void
* @access public
*/
- public function error($error)
- {
- // make the variables static so that is only has to do the defining
- // on the first call.
- static $errorMessages;
- static $className;
-
- // define the various error messages
- if (!isset($errorMessages)) {
- $className = get_class($this);
- $errorMessages = array(
- FORM_OK => 'No error',
- FORM_ERROR => 'Unknown error',
- NO_RECORD => 'Setting both properties (email and hasContactDB) to false in the <i>' . $className . '</i> class will result in no email record being sent and no record being inserted into the database. There will be no record that this form was ever filled out.',
- INVALID_DB => 'Please set the property hasContactDB to a boolean value in the class <i>' . $className . '</i> before continuing',
- MISSING_CONSTANT => 'You have failed to set a CONSTANT for the class <i>' . $className . '</i> to function properly',
- MISSING_CONTACT_TYPE => 'Please set the property contactType in the class <i>'. $className . '</i> before continuing',);
- }
-
- if (!is_null($error->message)) {
- $message = $error->message;
- } elseif (isset($errorMessages[$error->code])) {
- $message = $errorMessages[$error->code];
- } else {
- $message = $errorMessages[$error->code];
- $message = $errorMessages[FORM_ERROR];
- }
-
- echo "<div id=\"form-warning-top\">{$message}</div>";
- }
-
- // }}}
-
- // {{{ getInterestFields()
+ public function error($error)
+ {
+ // make the variables static so that is only has to do the defining
+ // on the first call.
+ static $errorMessages;
+ static $className;
+
+ // define the various error messages
+ if (!isset($errorMessages)) {
+ $className = get_class($this);
+ $errorMessages = array(
+ FORM_OK => 'No error',
+ FORM_ERROR => 'Unknown error',
+ NO_RECORD => 'Setting both properties (email and hasContactDB) to false in the <i>' . $className . '</i> class will result in no email record being sent and no record being inserted into the database. There will be no record that this form was ever filled out.',
+ INVALID_DB => 'Please set the property hasContactDB to a boolean value in the class <i>' . $className . '</i> before continuing',
+ MISSING_CONSTANT => 'You have failed to set a CONSTANT for the class <i>' . $className . '</i> to function properly',
+ MISSING_CONTACT_TYPE => 'Please set the property contactType in the class <i>'. $className . '</i> before continuing',);
+ }
+
+ if (!is_null($error->message)) {
+ $message = $error->message;
+ } elseif (isset($errorMessages[$error->code])) {
+ $message = $errorMessages[$error->code];
+ } else {
+ $message = $errorMessages[$error->code];
+ $message = $errorMessages[FORM_ERROR];
+ }
+
+ echo "<div id=\"form-warning-top\">{$message}</div>";
+ }
+
+ // }}}
+
+ // {{{ getInterestFields()
/**
* Returns the field definitions of the contact db interest fields
* @return array Group definitions for the interest fields
* @access protected
*/
- protected function getInterestFields()
- {
- if (is_array($this->inquiries)) {
+ protected function getInterestFields()
+ {
+ if (is_array($this->inquiries)) {
foreach ($this->inquiries as $group => $data) {
foreach ($data as $k => $v) {
$interests[$group][] = array(
'opts' => $v
);
}
- }
- }
+ }
+ }
- return $interests;
- }
+ return $interests;
+ }
- // }}}
+ // }}}
- // {{{ processData()
+ // {{{ processData()
/**
* Handles how to process the form when submitted
*
* @param array $values Form submitted values
- *
+ *
* @return array Result of Insert / Update function
* @access protected
*/
- public function processData($values)
- {
- // Form data used for the insert/update sql queries and
- // the form email.
- $e = array(
- 'user_agent',
- 'remote_addr',
- 'contact_type',
- );
- $this->setFormData($e);
+ public function processData($values)
+ {
+ // Form data used for the insert/update sql queries and
+ // the form email.
+ $e = array(
+ 'user_agent',
+ 'remote_addr',
+ 'contact_type',
+ );
+ $this->setFormData($e);
$this->start = $values['start'];
unset($values['start']);
// Get rid of any elements in the values array that
$values['contact_type'] = '';
}
- if ($isUpdate) {
+ if ($isUpdate) {
$this->Action = 'Contact Updated';
- } else {
+ } else {
$this->Action = 'Contact Added';
- }
+ }
$values['create_date'] = date('m/d/Y');
// build a contact or customer class object with the values from
// the Contact form
$contact->save($this->dbh, false);
return true;
- }
+ }
- // }}}
+ // }}}
// {{{ setConfig()
/**
* setConfig
{
$this->config = $c;
}// }}}
- // {{{ setInterestFields()
+ // {{{ setInterestFields()
/**
* Contact DB interests
* @return void
* @access protected
*/
- protected function setInterestFields()
- {
- try {
- $sql = "
+ protected function setInterestFields()
+ {
+ try {
+ $sql = "
SELECT contact_inq.*, inq_group.name
FROM contact_inq LEFT OUTER JOIN inq_group ON (contact_inq.groupid = inq_group.id)
ORDER BY groupid, pos";
$i = array();
- foreach ($this->dbh->query($sql) as $row) {
- $i[$row['name']][$row['id']] = $row['header'];
- }
+ foreach ($this->dbh->query($sql) as $row) {
+ $i[$row['name']][$row['id']] = $row['header'];
+ }
- $this->inquiries = $i;
- } catch (PDOException $e) {
- Toolkit_Common::handleError($e);
- }
- }
+ $this->inquiries = $i;
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
- // }}}
+ // }}}
// {{{ setPrimaryKey()
/**
* setPrimaryKey
$this->tableName = $tableName;
}// }}}
- // {{{ setupRenderers()
+ // {{{ setupRenderers()
// @codeCoverageIgnoreStart
/**
* @return void
* @access protected
*/
- protected function setupRenderers()
- {
- parent::setupRenderers();
- $renderer =& $this->defaultRenderer();
- $required = '<!-- BEGIN required -->
+ protected function setupRenderers()
+ {
+ parent::setupRenderers();
+ $renderer =& $this->defaultRenderer();
+ $required = '<!-- BEGIN required -->
<span class="req"> * </span>
<!-- END required -->';
- $error = '<!-- BEGIN error -->
+ $error = '<!-- BEGIN error -->
<div class="req"> {error} </div>
<!-- END error -->';
- $renderer->setElementTemplate(
+ $renderer->setElementTemplate(
'<tr>
<td colspan="2" class="fieldcell checkbox">
'.$required.'{label}'.$error.'{element}
'{element}',
'interest['.$group.']'
);
- $renderer->setElementTemplate(
+ $renderer->setElementTemplate(
'<tr>
<td colspan="2">'.$required.'{label}'.$error.'{element}
</td>
);
}
}
- $renderer->setElementTemplate(
+ $renderer->setElementTemplate(
'<tr><td colspan="2">'.$required.'{label}'.$error.'{element}</td></tr>',
'comments'
);
- $renderer->setElementTemplate(
+ $renderer->setElementTemplate(
'<tr align="center">
<td colspan="2">'.$required.'{label}'.$error.'{element}
</td>
'submit'
);
- $renderer->setElementTemplate(
+ $renderer->setElementTemplate(
'<tr>
<td class="labelcell">
<label>{label}</label>
</td>
</tr>',
'captcha_question');
- $renderer->setElementTemplate(
+ $renderer->setElementTemplate(
'<tr>
<td class="labelcell">
'.$required.'<label>{label}</label>
</tr>',
'captcha_rmv'
);
- }
+ }
// @codeCoverageIgnoreEnd
- // }}}
- // {{{ toHtml()
+ // }}}
+ // {{{ toHtml()
/**
* Handles how to display the current step the user is at in the form
*
- * destroying and resetting the captcha value dis-allows someone from
- * re-sending a form on a previous captcha.
- *
+ * destroying and resetting the captcha value dis-allows someone from
+ * re-sending a form on a previous captcha.
+ *
* @return string form HTML state
* @access public
*/
- public function toHtml()
- {
- $this->setupRenderers();
- if ($this->validate()) {
- $this->cleanForm();
- if ($this->process(array(&$this, 'processData'), $this->mergeFiles)) {
- $this->freeze();
- $output = $this->successMsg;
+ public function toHtml()
+ {
+ $this->setupRenderers();
+ if ($this->validate()) {
+ $this->cleanForm();
+ if ($this->process(array(&$this, 'processData'), $this->mergeFiles)) {
+ $this->freeze();
+ $output = $this->successMsg;
header("Location: list_contact.phtml?back=1&start="
. $this->start . "&Action=" . $this->Action);
exit;
- }
- } elseif ($this->isSubmitted()) {
- $output = $this->errorMsg;
- $output .= parent::toHTML();
- } else {
- $output = parent::toHTML();
- }
- return $output;
- }
-
- // }}}
+ }
+ } elseif ($this->isSubmitted()) {
+ $output = $this->errorMsg;
+ $output .= parent::toHTML();
+ } else {
+ $output = parent::toHTML();
+ }
+ return $output;
+ }
+
+ // }}}
}