From: Laury GvR The system has encountered an un-recoverable error! ' . self::getErrorInfo($e) . '";
+ }
+
+ // }}}
+ // {{{ createLink()
+
+
+ /**
+ * Creates a folder link so we can browse to each folder
+ *
+ * @param array $row Folder information
+ *
+ * @return string anchor link for folder
+ * @access protected
+ */
+ protected function createLink(array $row)
+ {
+ $format = '%s';
+
+ $link = sprintf(
+ $format,
+ ($_GET['folder'] == $row['id']) ? 'clicked' : null,
+ $_GET['CKEditor'],
+ $_GET['CKEditorFuncNum'],
+ $_GET['langCode'],
+ $row['id'],
+ $row['name']
+ );
+
+ return $link;
+ }
+
+ // }}}
+
+ // {{{ fetchFoldersArray()
+
+
+ /**
+ * Fetches a tree hierarchy of the folder structure into a linear array
+ *
+ * @param integer $start node to start at
+ *
+ * @return array folder structure with levels
+ * @access protected
+ */
+ protected function fetchFoldersArray($start)
+ {
+ return Toolkit_Common::getHierarchicalTreeStructure(
+ $this->dbh,
+ 'ckeditor_folders',
+ 'id',
+ 'parent',
+ 'id',
+ $start
+ );
+ }
+
+ // }}}
+
+ // {{{ getFolders()
+
+
+ /**
+ * Gets the folders ul list
+ *
+ * @param integer $parent start at a certain level
+ *
+ * @return string list of folders
+ * @access public
+ */
+ public function getFolders($parent = 0)
+ {
+ $folders = $this->fetchFoldersArray($parent);
+ try {
+ $sql = "
+ SELECT *
+ FROM ckeditor_folders
+ WHERE id = :id";
+
+ $stmt = $this->dbh->prepare($sql);
+ foreach ($folders as $i => $j) {
+ $stmt->bindParam(':id', $i, PDO::PARAM_INT);
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if ($j == $this->_prevLvl) {
+ $tree .= $this->openNode($row);
+ $tree .= $this->createLink($row);
+ $this->_prevLvl = $j;
+ } elseif ($j > $this->_prevLvl) {
+ ++$this->_lvlsOpen;
+ $tree .= $this->createFolder();
+ $tree .= $this->openNode($row);
+ $tree .= $this->createLink($row);
+ $this->_prevLvl = $j;
+ } elseif ($j < $this->_prevLvl) {
+ do {
+ $tree .= $this->closeNode();
+ $tree .= $this->closeFolder();
+ } while (--$this->_lvlsOpen > $j);
+ $tree .= $this->closeNode();
+ $tree .= $this->openNode($row);
+ $tree .= $this->createLink($row);
+ $this->_prevLvl = $this->_lvlsOpen;
+ }
+ }
+ $tree .= $this->closeFolder();
+ return $tree;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ openNode()
+
+
+ /**
+ * Opens a branch or leaf node
+ *
+ * @param array $row Folder information
+ *
+ * @return string opening li tag
+ * @access protected
+ */
+ protected function openNode(array $row)
+ {
+ return "\n\t
GLM Image Browser
+
+
+
+
+
+
+
+ * public function &emailRenderElement($e)
+ * {
+ * switch ($e) {
+ * case 'element_one' :
+ * case 'element_two' :
+ * case 'element_three' :
+ * $renderer =& $this->defaultRenderer();
+ * $renderer->clearAllTemplates();
+ * $renderer->setGroupTemplate('{content}', $e);
+ * $renderer->setGroupElementTemplate('{element}
+ *
+ * @param array $newLabels Assoc array of element names and new
+ * labels to be used in the email form.
+ * eg [$newLabels['element'] => 'Label']
+ * @param array $excludeList Any element that needs to be removed
+ * from the form when creating the table
+ * eg [$list = array(e1, e2, e3, etc..)]
+ *
+ * @return mixed The table body for the email.
+ */
+ public function createEmailBody(
+ array $newLabels = array(),
+ array $excludeList = array()
+ ) {
+ $this->freeze();
+ // Get the values corresponding to the elements present in the form.
+ $formData = $this->exportValues();
+ // The array keys holds all the names of the elements.
+ $elements = array_keys($formData);
+ // Remove any unwanted elements from our elements array.
+ foreach ($excludeList as $trgt) {
+ unset($elements[array_search($trgt, $elements)]);
+ }
+
+ // Which row we are at.
+ $i = 0;
+ $table = new HTML_Table(array('class' => 'data'));
+ // Auto grow the table, since the forms will by dynamic in size.
+ $table->setAutoGrow(true);
+ // Get the labels and values of the elements.
+ foreach ($elements as $name) {
+ $e =& $this->getElement($name);
+ // Get the default HTML for each element.
+ $html = $e->toHtml();
+ // If any elements need to have their html
+ // changed for an email, this function in the
+ // class should exist and will return a renderer
+ // object of how the element should be rendered.
+ if (method_exists($this, 'emailRenderElement')) {
+ $renderer =& $this->emailRenderElement($name);
+ // make sure we have an actual rendering object
+ // if the element doesn't need to be altered it should
+ // just return null.
+ if (is_object($renderer)) {
+ $e->accept($renderer);
+ $html = $renderer->toHtml($name);
+ // We have to reset the entire forms html
+ // otherwise we'll just keep adding to it everytime
+ // we render a new element.
+ // This is a bit of a hack to make this work (because
+ // the _html element is supposed to be a private
+ // property)
+ $renderer->_html = null;
+ }
+ }
+ // Get the label for the element.
+ $label = array_key_exists($name, $newLabels) ?
+ $newLabels[$name] :
+ $e->getLabel();
+
+ // Make the row and increment the row counter.
+ $table->setCellContents($i, 0, $label);
+ $table->setCellAttributes($i, 0, array('class' => 'label'));
+ $table->setCellAttributes($i, 1, array('class' => 'field'));
+ $table->setCellContents($i++, 1, $html);
+ }
+ return $table->toHtml();;
+ }
+
+ // }}}
+ // {{{ createSQLInsert()
+
+ /**
+ * Generates a properly formatted sql query to insert data into a table
+ *
+ * @param string $table Name of the table to insert into
+ * @param array $columns Array of column names you want to set in the
+ * insert statement and bind names
+ *
+ *
', $e);
+ * break;
+ *
+ * default :
+ * $renderer = null;
+ * break;
+ * }
+ *
+ * return $renderer;
+ * }
+ *
+ * Toolkit_Common::createSQLInsert('member', array('name', 'pos'));
+ * will create the sql statement
+ * INSERT INTO member (name, pos) VALUES(:name, :pos)
+ *
+ *
+ * @return string Formatted SQL string
+ * @access public
+ * @static
+ */
+ public static function createSQLInsert($table, array $columns)
+ {
+ $params = implode(', ', $columns);
+ $bindParams = ':' . implode(', :', $columns);
+
+ return "INSERT INTO $table ($params) VALUES ($bindParams)";
+ }
+
+ // }}}
+ // {{{ createSQLUpdate()
+
+ /**
+ * Generates a properly formatted sql query to update data in a table
+ *
+ *
+ * Toolkit_Common::createSQLUpdate('member',
+ * array('name', 'pos'),
+ * array('id = :id');
+ * will create the sql statement
+ * UPDATE member SET name = :name, pos = :pos WHERE id = :id
+ *
+ *
+ * @param string $table Name of the table to update
+ * @param array $columns Array of columns names you want to update
+ * @param array $constraints Constraints to apply to the table to prevent
+ * running the update on every row in the db
+ *
+ * @return string formatted query string
+ * @access public
+ * @static
+ */
+ public static function createSQLUpdate(
+ $table,
+ array $columns,
+ array $constraints = null
+ ) {
+ $length = count($columns);
+ for ($i = 0; $i < $length; ++$i) {
+ $bindParams .= "{$columns[$i]} = :{$columns[$i]}";
+ if ($i < ($length - 1)) {
+ $bindParams .= ', ';
+ }
+ }
+ $sql = "UPDATE $table SET $bindParams";
+
+ if (!empty($constraints)) {
+ $sql .= ' WHERE ' . implode(' AND ', $constraints);
+ }
+
+ return $sql;
+ }
+
+ // }}}
+ // {{{ createTables()
+
+ /**
+ * Read file from parameter and use the PDO parameter to create process file
+ *
+ * @param PDO $pdo PHP Data Object to use for DB calls
+ * @param string $file full path of file to parse
+ *
+ * @return void
+ * @access public
+ * @static
+ */
+ public static function createTables(PDO $pdo, $file)
+ {
+ $sql = file_get_contents($file);
+ // break multiple queries apart by ';'
+ $tok = strtok($sql, ';');
+ try {
+ // while we have valid tokens, execute the query
+ // and grab the next token
+ while ($tok !== false) {
+ $pdo->query($tok);
+ $tok = strtok(';');
+ }
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ dieGracefully()
+
+ /**
+ * Gracefully exit from the script when an unrecoverable error is created
+ *
+ * @param string $msg Message to display to user
+ * @param mixed $e Error object
+ * @param boolean $moreInfo More debugging info when in development
+ *
+ * @return void
+ * @access public
+ */
+ public function dieGracefully($msg = null, $e = null, $moreInfo = false)
+ {
+ if (is_null($e)) {
+ if (is_null($msg)) {
+ die('There was an error, please try again later!');
+ } else {
+ die($msg);
+ }
+ } else {
+ echo $msg . '
';
+ echo 'Error Caught.
';
+ echo 'Error: ' . $e->getMessage() . '
';
+ if ($moreInfo) {
+ echo 'Code: ' . $e->getCode() . '
';
+ echo 'Debug Info: ' . $e->getDebugInfo() . '
';
+ }
+ }
+ }
+
+ // }}}
+
+ // {{{ errorException()
+
+ /**
+ * Stops script on Exception error
+ *
+ * Stops the script when an Exception is raised inside a
+ * try/catch block.
+ *
+ * When a site is no longer in DEVELOPMENT, ie: its live on ws3.
+ * We don't show any error info, but let the user know an unexpected
+ * error has occured and then mail the error info the the admin.
+ *
+ * Example usage:
+ *
+ * try {
+ if ($foo != $bar) {
+ throw new Exception ("Foo Doesn't equal Bar");
+ }
+ * } catch (Exception $e) {
+ * return Toolkit_Common::handleError($e);
+ * }
+ *
+ *
+ * @param Exception $e Exception Object
+ * @param Mail $mail What to use to send mail to admin
+ *
+ * @return false
+ * @access public
+ * @static
+ */
+ public static function errorException(Exception $e, Mail $mail = null)
+ {
+ if (!is_null($mail)) {
+ $subject = 'Exception Error for ' . SITENAME;
+ self::mailError($mail, $subject, $e);
+ } else {
+ echo self::getErrorInfo($e);
+ }
+
+ return false;
+ }
+
+ // }}}
+ // {{{ errorHTMLQuickFormError()
+
+ /**
+ * Handles PEAR Errors for our developers
+ *
+ * When a site is no longer in DEVELOPMENT, ie: its live on ws3.
+ * We don't show any error info, but let the user know an unexpected
+ * error has occured and then mail the error info the the admin.
+ *
+ * HTML_QuickForm Example usage:
+ *
+ * $e =& $this->getElement('elementName');
+ * if (PEAR::isError($e)) {
+ * return Toolkit_Common::handleError($e);
+ * }
+ *
+ *
+ * @param HTML_QuickForm_Error $e QuickFormError Object
+ * @param Mail $mail What to use to send mail to admin
+ *
+ * @return false
+ * @access public
+ * @since Method available since Release 1.0.1
+ * @static
+ */
+ public static function errorHTMLQuickFormError(
+ HTML_QuickForm_Error $e,
+ Mail $mail = null
+ ) {
+ if (!is_null($mail)) {
+ $subject = 'PEAR Error for ' . SITENAME;
+ self::mailError($mail, $subject);
+ } else {
+ echo self::getErrorInfo($e);
+ }
+
+ return false;
+ }
+
+ // }}}
+ // {{{ errorPDOException()
+
+ /**
+ * Stops script on database error
+ *
+ * Stops the script when a PDOException is raised inside a
+ * try/catch block.
+ *
+ * When a site is no longer in DEVELOPMENT, ie: its live on ws3.
+ * We don't show any error info, but let the user know an unexpected
+ * error has occured and then mail the error info the the admin.
+ *
+ * Example usage:
+ *
+ * try {
+ * $sql = "
+ * SELECT *
+ * FROM table_name
+ * WHERE id = :id";
+ *
+ * $stmt = $this->dbh->prepare($sql);
+ * $stmt->bindParam(':id', $id, PDO::PARAM_INT);
+ * return $stmt->execute();
+ * } catch (PDOException $e) {
+ * return Toolkit_Common::handleError($e);
+ * }
+ *
+ *
+ * @param PDOException $e PDO Error Object.
+ * @param Mail $mail Mail object used to send admin email
+ *
+ * @return false
+ * @access public
+ * @since Method available since Release 1.0.1
+ */
+ public function errorPDOException(PDOException $e, Mail $mail = null)
+ {
+ if (!is_null($mail)) {
+ $subject = 'SQL Error for ' . SITENAME;
+ self::mailError($mail, $subject, $e);
+ } else {
+ echo self::getErrorInfo($e);
+ }
+
+ return false;
+ }
+
+ // }}}
+ // {{{ errorPEARError()
+
+ /**
+ * Handles PEAR Errors for our developers
+ *
+ * When a site is no longer in DEVELOPMENT, ie: its live on ws3.
+ * We don't show any error info, but let the user know an unexpected
+ * error has occured and then mail the error info the the admin.
+ *
+ * @param PEAR_Error $e PEARError Object
+ * @param Mail $mail Mail object used to send admin email
+ *
+ * @return false
+ * @access public
+ * @since Method available since Release 1.0.1
+ */
+ public function errorPEARError(PEAR_Error $e, Mail $mail = null)
+ {
+ if (!is_null($mail)) {
+ $subject = 'PEAR Error for ' . SITENAME;
+ self::mailError($mail, $subject);
+ } else {
+ echo self::getErrorInfo($e);
+ }
+
+ return false;
+ }
+
+ // }}}
+ // {{{ errorPEARException()
+
+ /**
+ * Handles PEAR Exception for our developers
+ *
+ * When a site is no longer in DEVELOPMENT, ie: its live on ws3.
+ * We don't show any error info, but let the user know an unexpected
+ * error has occured and then mail the error info the the admin.
+ *
+ * @param PEAR_Exception $e PEARException Object
+ * @param Mail $mail Mail object used to send admin email
+ *
+ * @return false
+ * @access public
+ * @since Method available since Release 1.0.1
+ */
+ public function errorPEARException(PEAR_Exception $e, Mail $mail = null)
+ {
+ if (!is_null($mail)) {
+ $subject = 'SQL Error for ' . SITENAME;
+ self::mailError($mail, $subject, $e);
+ } else {
+ echo self::getErrorInfo($e);
+ }
+
+ return false;
+ }
+
+ // }}}
+ // {{{ errorRuntimeException()
+
+ /**
+ * Stops script on runtime error
+ *
+ * Stops the script when a runtimeException is raised inside a
+ * try/catch block.
+ *
+ * When a site is no longer in DEVELOPMENT, ie: its live on ws3.
+ * We don't show any error info, but let the user know an unexpected
+ * error has occured and then mail the error info the the admin.
+ *
+ * @param RuntimeException $e PDO Error Object.
+ * @param Mail $mail Mail object used to send admin email
+ *
+ * @return false
+ * @access public
+ * @since Method available since Release 1.0.2
+ */
+ public function errorRuntimeException(
+ RuntimeException $e,
+ Mail $mail = null
+ ) {
+ if (!is_null($mail)) {
+ $subject = 'Runtime Exception for ' . SITENAME;
+ self::mailError($mail, $subject, $e);
+ } else {
+ echo self::getErrorInfo($e);
+ }
+
+ return false;
+ }
+
+ // }}}
+ // {{{ errorBadMethodCallException()
+
+ /**
+ * Stops script on bad method call error
+ *
+ * Stops the script when a badMethodCallException is raised inside a
+ * try/catch block.
+ *
+ * When a site is no longer in DEVELOPMENT, ie: its live on ws3.
+ * We don't show any error info, but let the user know an unexpected
+ * error has occured and then mail the error info the the admin.
+ *
+ * @param BadMethodCallException $e PDO Error Object.
+ * @param Mail $mail Mail object used to send admin email
+ *
+ * @return false
+ * @access public
+ * @since Method available since Release 1.0.3
+ */
+ public function errorBadMethodCallException(
+ BadMethodCallException $e,
+ Mail $mail = null
+ ) {
+ if (!is_null($mail)) {
+ $subject = 'Bad Method Call Exception for ' . SITENAME;
+ self::mailError($mail, $subject, $e);
+ } else {
+ echo self::getErrorInfo($e);
+ }
+
+ return false;
+ }
+
+ // }}}
+
+ // {{{ filterURI()
+
+ /**
+ * Filters uri's before they are validated
+ *
+ * @param string $uri URI to filter
+ *
+ * @return mixed new uri if missing scheme
+ * @access public
+ * @static
+ */
+ public static function filterURI($uri)
+ {
+ $validProtocol = '/^https?\:\/\/.*/';
+ $invalidProtocol = '/^.*?\:\/\/.*/';
+ if (empty($uri)) {
+ // Empty field, just return
+ return $uri;
+ } elseif (preg_match($validProtocol, $uri)) {
+ // has valid protocol, return unchanged
+ // should pass validation.
+ return $uri;
+ } elseif (!preg_match($invalidProtocol, $uri)) {
+ // missing protocol, prepend default
+ // http:// protocol and return.
+ return "http://$uri";
+ } else {
+ // has invalid protocol, return unchanged
+ // validation should catch this and throw error.
+ return $uri;
+ }
+ }
+
+ // }}}
+ // {{{ filterPhone()
+
+ /**
+ * Filters phone numbers before they are validated
+ *
+ * @param string $phone number to filter
+ *
+ * @return mixed newly formatted phone number
+ * @access public
+ * @static
+ */
+ public static function filterPhone($phone)
+ {
+ // Ditch anything that is not a number
+ $number = preg_replace('/[^0-9]/', '', $phone);
+
+ // Invalid Number, validation will catch error
+ $len = strlen($number);
+ if (($len < 10) || ($len > 11)) {
+ return $phone;
+ }
+
+ // subscriber number
+ $sn = substr($number, -4);
+ // city code
+ $cc = substr($number, -7, 3);
+ // area code
+ $ac = substr($number, -10, 3);
+ if ($len == 11) {
+ // country prefix
+ $cp = $number[0];
+ }
+
+ $filteredNumber = "($ac) $cc-$sn";
+ if (!is_null($cp)) {
+ $filteredNumber = "$cp $filteredNumber";
+ }
+
+ return $filteredNumber;
+ }
+
+ // }}}
+
+ // {{{ getCities()
+
+ /**
+ * Get an array of cities from the database
+ *
+ * @param PDO $dbh Database handler
+ * @param integer $state State id the city is in
+ * @param integer $county County id the city is in
+ * @param integer $region Region id the city is in
+ *
+ * @return array states
+ * @access public
+ * @static
+ */
+ public static function getCities(
+ PDO $dbh,
+ $state = null,
+ $county = null,
+ $region = null
+ ) {
+ $param = array();
+ if (ctype_digit((string)$state)) {
+ $param[] = 'state_id = ' . $dbh->quote($state);
+ }
+ if (ctype_digit((string)$county)) {
+ $param[] = 'county_id = ' . $dbh->quote($county);
+ }
+ if (ctype_digit((string)$region)) {
+ $param[] = 'region_id = ' . $dbh->quote($region);
+ }
+
+ try {
+ $sql = "
+ SELECT *
+ FROM city";
+
+ if (!empty($param)) {
+ $sql .= ' WHERE ' . implode(' AND ', $param);
+ }
+ $sql .= ' ORDER BY city_name';
+
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute();
+
+ $cities = array();
+ while ($row = $stmt->fetch()) {
+ $cities[$row['city_id']] = $row['city_name'];
+ }
+
+ return $cities;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ getErrorInfo()
+
+ /**
+ * extract error info from error object
+ *
+ * @param mixed $obj Error object to get info for
+ *
+ * @return string formatted error information
+ * @access public
+ */
+ public function getErrorInfo($obj)
+ {
+ $state = '' . get_class($obj) . ' error: ';
+
+ $state .= '
$_SERVER[\'QUERY_STRING\']: ' . $_SERVER['QUERY_STRING']
+ . "\n";
+ $state .= '
$_SERVER[\'HTTP_REFERER\']: ' . $_SERVER['HTTP_REFERER']
+ . "\n";
+ $state .= '
$_SERVER[\'REDIRECT_QUERY_STRING\']: '
+ . $_SERVER['REDIRECT_QUERY_STRING'] . "\n";
+ $state .= '
$_SERVER[\'REQUEST_URI\']: ' . $_SERVER['REQUEST_URI']
+ . "\n";
+
+ $state .= '
$_GET: ' . print_r($_GET, true) . '
';
+ $state .= '
$_POST: ' . print_r($_POST, true) . '
';
+ $state .= '
$_SESSION: ' . print_r($_SESSION, true) . '
';
+
+ if (method_exists($obj, 'getMessage')) {
+ $state .= $obj->getMessage();
+ if (method_exists($obj, 'getDebugInfo')) {
+ $state .= '; ' . $obj->getDebugInfo();
+ }
+ }
+ if (method_exists($obj, 'getFile')) {
+ $state .= ' in ' . $obj->getFile() . '';
+ }
+ if (method_exists($obj, 'getLine')) {
+ $state .= ' on line ' . $obj->getLine() . '';
+ }
+ if (method_exists($obj, 'getBacktrace')) {
+ $backtrace = print_r($obj->getBacktrace(), true);
+
+ $state .= "$backtrace
";
+ }
+
+ return $state;
+ }
+
+ // }}}
+ // {{{ getHierarchicalTreeStructure()
+
+ /**
+ * Create a hierarchical tree stored in an linear array
+ *
+ * Produces a representation of a hierarchical tree structure into a
+ * linear array so you can iterate straight through to get the tree
+ * structure.
+ *
+ * @param PDO $pdo Database handler
+ * @param string $table Name of the source relation
+ * @param string $key Name of the key field
+ * @param string $parent Name of the parent-key field
+ * @param string $order Name of the field to order siblings by
+ * @param integer $start Key value of the row to start at
+ * @param integer $maxDepth Maximum depth to descend to, or zero
+ * for unlimited depth
+ * @param boolean $validParent exclude branches that have null
+ * parent values
+ *
+ * @return array Linear array of tree structure
+ * @access public
+ * @see http://www.postgresql.org/doc/8.3/interactive/tablefunc.html#AEN104085
+ */
+ public function getHierarchicalTreeStructure(
+ PDO $pdo,
+ $table = 'pages',
+ $key = 'id',
+ $parent = 'parent',
+ $order = 'pos',
+ $start = 0,
+ $maxDepth = 0,
+ $validParent = true
+ ) {
+ try {
+ $tree = array();
+
+ $sql = "
+ SELECT *
+ FROM connectby('{$table}', '{$key}', '{$parent}',
+ '{$order}', '{$start}', {$maxDepth})
+ as t(id text, parent text, level int, pos int)";
+ if ($validParent) {
+ $sql .= " WHERE parent is not null";
+ }
+ foreach ($pdo->query($sql) as $row) {
+ $tree[$row['id']] = $row['level'];
+ }
+
+ return $tree;
+ } catch (PDOException $e) {
+ return self::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ getScripts()
+
+ /**
+ * Gets all scripts for the page
+ *
+ * adds version number to url for all local (non-app.glm) urls
+ * so we can use .htaccess cachebusting
+ *
+ * combines script by server id, so we can decrease http requests to fetch
+ * the needed scripts
+ *
+ * @param array $scripts The array of js scripts for the page
+ *
+ * @return string HTML markup for scripts
+ * @access public
+ * @static
+ */
+ public static function getScripts(array $scripts)
+ {
+ if (!is_array($scripts) || empty($scripts)) {
+ return false;
+ }
+
+ $uniqueScripts = array_unique($scripts);
+ // Get the main jquery file
+ $jquery = JQUERY_CDN_JS;
+ $key = array_search($jquery, $uniqueScripts);
+ // If it exists, remove it from its current location
+ // and put at front of array.
+ if ($key !== false) {
+ unset($uniqueScripts[$key]);
+ array_unshift($uniqueScripts, $jquery);
+ }
+ $format = '';
+
+ $ret = '';
+ $baseUrlStrLen = strlen(MEDIA_BASE_URL);
+ $appUrlStrLen = strlen(MEDIA_APP_BASE_URL);
+
+ // Use versioning with local scripts for cachebusting
+ $localPath = MEDIA_BASE_URL . 'v/' . VERSION . '/javascript/';
+ $appPath = MEDIA_APP_BASE_URL . 'javascript/';
+
+ $localScripts = array();
+ $appScripts = array();
+ foreach ($uniqueScripts as $origScript) {
+ $ret .= sprintf($format, $origScript) . "\n";
+ }
+
+ if (!empty($appScripts)) {
+ $appPath = $appPath . implode(',', $appScripts);
+ $ret .= sprintf($format, $appPath) . "\n";
+ }
+
+ if (!empty($localScripts)) {
+ $localPath = $localPath . implode(',', $localScripts);
+ $ret .= sprintf($format, $localPath) . "\n";
+ }
+
+ return $ret;
+ }
+
+ // }}}
+ // {{{ getStates()
+
+
+ /**
+ * Get an array of states from the database
+ *
+ * @param PDO $dbh Database handler
+ * @param boolean $unionStatesOnly If we want to only retrieve
+ * the 50 US states
+ *
+ * @return array states
+ * @access public
+ * @static
+ */
+ public static function getStates(PDO $dbh, $unionStatesOnly = false)
+ {
+ if ($unionStatesOnly) {
+ // Just grab the 50 states of the union
+ $where = "WHERE us_state = :bool";
+ }
+
+ try {
+ $sql = "
+ SELECT *
+ FROM state
+ $where
+ ORDER BY state_name";
+
+ $stmt = $dbh->prepare($sql);
+ if ($unionStatesOnly) {
+ $stmt->bindValue(':bool', 1, PDO::PARAM_BOOL);
+ }
+ $stmt->execute();
+
+ $states = array();
+ while ($row = $stmt->fetch()) {
+ $states[$row['state_id']] = $row['state_name'];
+ }
+
+ return $states;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ getStyleSheets()
+
+ /**
+ * Gets all style sheets for the page
+ *
+ * adds version number to url for all local (non-app.glm) urls
+ * so we can use .htaccess cachebusting
+ *
+ * combines style sheets by server id, so we can decrease http
+ * requests to fetch the needed style sheets
+ *
+ * @return string HTML markup for stylesheets
+ * @access public
+ * @static
+ */
+ public static function getStyleSheets()
+ {
+ if ( !isset($GLOBALS['styleSheets'])
+ || !is_array($GLOBALS['styleSheets'])
+ || empty($GLOBALS['styleSheets'])
+ ) {
+ return false;
+ }
+
+ $uniqueStyleSheets = array_unique($GLOBALS['styleSheets']);
+ $format = '';
+
+ $baseUrlStrLen = strlen(MEDIA_BASE_URL);
+ $appUrlStrLen = strlen(MEDIA_APP_BASE_URL);
+ $ret = '';
+
+ $localPath = MEDIA_BASE_URL . 'v/' . VERSION . '/css/';
+ $appPath = MEDIA_APP_BASE_URL . 'css/';
+
+ $localStyleSheets = array();
+ $appStyleSheets = array();
+ foreach ($uniqueStyleSheets as $origStyleSheet) {
+ $ret .= sprintf($format, $origStyleSheet) . "\n";
+ }
+
+ if (!empty($appStyleSheets)) {
+ $appPath = $appPath . implode(',', $appStyleSheets);
+ $ret .= sprintf($format, $appPath) . "\n";
+ }
+ if (!empty($localStyleSheets)) {
+ $localPath = $localPath . implode(',', $localStyleSheets);
+ $ret .= sprintf($format, $localPath) . "\n";
+ }
+
+ return $ret;
+ }
+
+ // }}}
+ // {{{ getTableMetaData()
+
+ /**
+ * Gets the meta data of the calling classes table columns
+ *
+ * The table used when retrieving the meta data is defined
+ * in the class property $tableName. The class or parent class
+ * must also have a $tableMetaData property
+ *
+ * @param PDO $pdo Database Handler
+ * @param string $tableName The name of the table to get the meta data for.
+ * @param array $clauses Only retrieve meta data for certain column types
+ *
+ * @return array metadata for table
+ * @access protected
+ */
+ public function getTableMetaData(
+ PDO $pdo,
+ $tableName,
+ array $clauses = null
+ ) {
+ if (is_array($clauses)) {
+ while ($c = current($clauses)) {
+ $ands .= " data_type = '{$c}'";
+ if (false !== next($clauses)) {
+ $ands .= " OR ";
+ }
+ }
+ $ands = " AND ($ands)";
+ }
+ try {
+ $sql = "
+ SELECT column_name, data_type
+ FROM information_schema.columns
+ WHERE table_name = :tname
+ $ands";
+ $stmt = $pdo->prepare($sql);
+ $stmt->bindParam(':tname', $tableName, PDO::PARAM_STR);
+
+ $stmt->execute();
+
+ $metaData = array();
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $metaData[$row['column_name']] = $row['data_type'];
+ }
+
+ return $metaData;
+ } catch (PDOException $e) {
+ return self::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ handleError()
+
+ /**
+ * Handles various script error
+ *
+ * @param Object $e Error Object
+ * @param boolean $developmentServer If we are on a development server
+ *
+ * @return mixed String, false, void
+ * @access public
+ * @static
+ */
+ public static function handleError($e, $developmentServer = DEVELOPMENT)
+ {
+ $errorType = str_replace('_', '', get_class($e));
+ $errorType = "error$errorType";
+
+ if (method_exists(__CLASS__, $errorType)) {
+ if (!$developmentServer) {
+ // Tell the user we encountered an Error.
+ if (file_exists(BASE . '404.html')) {
+ include_once BASE . "404.html";
+ }
+
+ $mail = Mail::factory('mail');
+ self::$errorType($e, $mail);
+ exit();
+ } else {
+ return self::$errorType($e, $mail);
+ }
+ } else {
+ echo '
+ * $rules[] = array('element' => 'phone',
+ * 'message' => 'ERROR: Invalid Phone Format!',
+ * 'type' => 'phone',
+ * 'format' => null,
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ *
+ *
+ * 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.
+ *
+ * $rules[] = array('element' => 'zip',
+ * 'message' => 'ERROR: Invalid Zip!',
+ * 'type' => 'zip',
+ * 'format' => array('requireDBCheck' => true),
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ *
+ *
+ * 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.
+ *
+ * $rules[] = array('element' => 'state_id',
+ * 'message' => 'ERROR: Invalid State / Province!',
+ * 'type' => 'state',
+ * 'format' => array('requireDBCheck' => true),
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ *
+ *
+ * @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 $action (optional)Form's action
+ * @param string $target (optional)Form's target defaults to '_self'
+ * @param mixed $attributes (optional)Extra attributes for
We will email you a link to the PDF version of the {brochure}.
+ORDER BY MAIL:
+{contactForm:h} diff --git a/Toolkit/Contacts/templates/contactForm.html b/Toolkit/Contacts/templates/contactForm.html new file mode 100644 index 0000000..2f2f84a --- /dev/null +++ b/Toolkit/Contacts/templates/contactForm.html @@ -0,0 +1,92 @@ ++ {sec.header:h} | +||||||||
+ | {elem.html:h} | +|||||||
+ {if:elem.required}*{end:}
+ {if:elem.error} {end:}
+ {elem.label:h} {end:}
+ {else:}
+ {if:elem.isType(#CAPTCHA_Image#)}
+ + {if:elem.error} |
+ {if:elem.required}*{end:}
+ {if:elem.error} {end:}
+ {elem.label:h}
+ {if:elem.error} {end:}
+ |
+ + {else:} + {if:elem.isType(#group#)} + |
+ {if:elem.required}*{end:}
+ {if:elem.error} {end:}
+ {elem.label:h} {end:}
+ {else:}
+ + {if:elem.error} |
+ {if:elem.required}*{end:}
+ {if:elem.error} {end:}
+ {elem.label:h}
+ {if:elem.error} {end:}
+ |
+ {if:elem.isName(#interest#)}
+ + {else:} + |
+ {end:}
+ {end:}
+ {end:}
+ {end:}
+ {if:elem.error} {elem.error} {end:}
+ {if:elem.isType(#group#)}
+ {foreach:elem.elements,gitem}
+ {gitem.label:h}
+ {gitem.html:h}{if:gitem.required}* {end:}
+ {if:elem.separator}{elem.separator:h}{end:}
+ {end:}
+ {else:}
+ {elem.html:h}
+ {if:elem.isName(#captcha_rmv#)}
+ What is this?
+
+ {end:}
+ {end:}
+ |
+
Below is the list of businesses you have added to your Trip Planner. The form below will be sent to each individual business listing that has an email address listed with their business listing. For those businesses with no email address, we have included their phone numbers for you to call directly and request additional information.
+These business listings have no current email address on file. To receive additional information please call the phone numbers listed next to each business name.
+Name + | Phone + | + |
---|---|---|
{member[memberName]} | +{member[memberPhone]} | +Remove | +
This list of businesses will receive the following information form directly to their email account.
+{member[memberName]} | +Remove | +
+ + {subject:h} + +
++ + From {fname:h} {lname:h} + +
+
+
|
+ |||
+
|
+
Dear {fname}
+Your friend {yname} has been to demo.gaslightmedia.com, and thought you might be interested in it.
+Message here.
+Thank you for requesting the {pdfName} Link. Here is the link to the Adobe PDF version: +
+Brochure ({pdfFileSize})
+Thank you for your interest in {client_info[name]:h}'!
+Sincerely,
+{client_info[name]:h}
+{client_info[url]:h}
+ + + diff --git a/Toolkit/DataGridBuilder.php b/Toolkit/DataGridBuilder.php new file mode 100644 index 0000000..ced09b6 --- /dev/null +++ b/Toolkit/DataGridBuilder.php @@ -0,0 +1,288 @@ + + * @license http://www.gaslightmedia.com Gaslightmedia + * @link http://demo.gaslightmedia.com + */ + +/** + * Create Datagrids for displaying data + * + * This abstract class handles all the base functionality of creating + * handeling all the details associated w/ a regular dataGrid. + * 1. Creation + * 2. Sorting (via column headers or sortform) + * 3. Pagenation + * + * @category Structures + * @package Toolkit_DataGridBuilder + * @author Jamie Kahgee
+ * protected $email = false;
+ *
+ *
+ * @var unknown
+ * @access protected
+ */
+ protected $email;
+
+ /**
+ * From header in the owner email
+ *
+ * This just sets the From header in the owner email
+ * SITENAME {v[label]:h} | + {if:v[nowrap]} +{v[element]:h} | + {else:} +{v[element]:h} | + {end:} +
A new Event has been added to your Website from your "Add Your Event" page.
+To approve it, please go to the Pending Events page in your admin.
+ + diff --git a/Toolkit/FileServer/AdapterAbstract.php b/Toolkit/FileServer/AdapterAbstract.php new file mode 100644 index 0000000..36e214a --- /dev/null +++ b/Toolkit/FileServer/AdapterAbstract.php @@ -0,0 +1,416 @@ + + * @copyright 2010 Jamie Kahgee + * @license http://www.gaslightmedia.com/ Gaslightmedia + * @version CVS: $Id: AdapterAbstract.php,v 1.6 2010/06/04 11:33:54 jamie Exp $ + * @link <> + * @see References to other sections (if any)... + */ + + +/** + * Validation Secret + */ +define('IS_VALIDATE_SECRET', 'Glm0IS1secreT'); + +/** + * URL to file server, this is dynamic based on the server + * so can be setup for any sandbox + */ +define('IS_SUBMIT_URL', FILE_SERVER_URL . 'submit.phtml'); + +/** + * Adapter class for linking to the file server + * + * @category Toolkit + * @package FileServer + * @author Jamie Kahgee
+ * $this->ctrlObj['url'] = MEDIA_BASE_URL;
+ *
+ *
+ *
+ * public function configureElements()
+ * {
+ * $e = array();
+ *
+ * $e[] = array(
+ * 'type' => 'text',
+ * 'req' => false
+ * 'name' => 'text_field',
+ * 'display' => 'Text Label',
+ * );
+ * $e[] = array(
+ * 'type' => 'checkbox',
+ * 'req' => false
+ * 'name' => 'checkbox_field',
+ * 'display' => 'Checkbox Label',
+ * );
+ *
+ * // ... More Element Definitions
+ *
+ * $this->setupElements($e);
+ * }
+ *
+ *
+ * @access public
+ * @return void
+ */
+ //public function configureElements();
+
+ // }}}
+ // {{{ configureForm()
+
+ /**
+ * Calls all the configuration methods to configure a form for use
+ *
+ * @access public
+ * @return void
+ */
+ //public function configureForm();
+
+ // }}}
+ // {{{ configureRules()
+
+ /**
+ * Defines all element rules to be used for validation in the form
+ *
+ * At the bare minimum, this function needs to be called to setup the
+ * form rules, even if no extra rules are defined. Because it still
+ * creates all the required rules that are defined w/ each element.
+ *
+ *
+ * public function configureRules()
+ * {
+ * $r = array();
+ *
+ * $r[] = array(
+ * 'element' => 'text_field',
+ * 'message' => 'ERROR: 10 characters max!',
+ * 'type' => 'maxlength',
+ * 'format' => 10,
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false,
+ * );
+ * $r[] = array(
+ * 'element' => 'text_field',
+ * 'message' => 'ERROR: Numric characters only!',
+ * 'type' => 'numeric',
+ * 'format' => null,
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false,
+ * );
+ *
+ * // ... More Rule Definitions
+ *
+ * $this->setupRules($r);
+ * }
+ *
+ *
+ * @access public
+ * @return void
+ */
+ public function configureRules();
+
+ // }}}
+ // {{{ toHtml()
+
+ /**
+ * Get an html string that contains the form
+ *
+ * Check if the form needs to be validated (ie. it was submitted)
+ * Check if submitted data needs to be processed
+ *
+ * @access public
+ * @return string an html string that contains the entire form
+ */
+ public function toHtml();
+
+ // }}}
+}
diff --git a/Toolkit/FormBuilder.php b/Toolkit/FormBuilder.php
new file mode 100644
index 0000000..4eb5592
--- /dev/null
+++ b/Toolkit/FormBuilder.php
@@ -0,0 +1,1264 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: FormBuilder.php,v 1.48 2010/08/05 14:19:47 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ */
+
+/**
+ * Allow the inclusion of the Element Grid plugin for QuickForms
+ */
+require_once 'HTML/QuickForm/ElementGrid.php';
+
+/**
+ * Handle QuickForm CAPTCHA's
+ */
+require_once 'HTML/QuickForm/CAPTCHA/Image.php';
+
+/**
+ * Require PEAR QuickForm class
+ */
+require_once 'HTML/QuickForm.php';
+
+require_once 'HTML/QuickForm/Rule/Zip.php';
+require_once 'HTML/QuickForm/Rule/Phone.php';
+require_once 'HTML/QuickForm/Rule/Banwords.php';
+require_once 'HTML/QuickForm/Rule/State.php';
+
+/**
+ * Base functionality for creating HTML_Quickforms
+ *
+ * @category Toolkit
+ * @package FormBuilder
+ * @author Jamie Kahgee
+ * $rules[] = array('element' => 'phone',
+ * 'message' => 'ERROR: Invalid Phone Format!',
+ * 'type' => 'phone',
+ * 'format' => null,
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ *
+ *
+ * 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.
+ *
+ * $rules[] = array('element' => 'zip',
+ * 'message' => 'ERROR: Invalid Zip!',
+ * 'type' => 'zip',
+ * 'format' => array('requireDBCheck' => true),
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ *
+ *
+ * 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.
+ *
+ * $rules[] = array('element' => 'state_id',
+ * 'message' => 'ERROR: Invalid State / Province!',
+ * 'type' => 'state',
+ * 'format' => array('requireDBCheck' => true),
+ * 'validation' => $this->validationType,
+ * 'reset' => true,
+ * 'force' => false);
+ *
+ *
+ * @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 string $formName Form's name.
+ * @param string $method (optional)Form's method defaults to 'POST'
+ * @param string $action (optional)Form's action
+ * @param string $target (optional)Form's target defaults to '_self'
+ * @param mixed $attributes (optional)Extra attributes for
+ * class exampleClass
+ * {
+ * $registeredRules = array(
+ * array(
+ * 'checkEmail',
+ * 'callback',
+ * 'email',
+ * 'Validate'
+ * )
+ * );
+ *
+ * // ... Rest of your class code
+ *
+ * public function configureRules()
+ * {
+ * $r = array();
+ *
+ * $r[] = array(
+ * 'element' => 'process_email',
+ * 'message' => 'ERROR: Invalid email format!',
+ * 'type' => 'checkEmail',
+ * 'format' => array('use_rfc822' => true),
+ * 'validation' => $this->validationType,
+ * 'reset' => false,
+ * 'force' => false
+ * );
+ *
+ * $this->setupRules($r);
+ * }
+ *
+ * // ... Rest of your class code
+ * }
+ *
+ *
+ * If the registeredRule is a string, the corresponding rule in the
+ * glmPEAR/HTML/QuickForm/Rule/ directory will be registered with
+ * the form.
+ *
+ * This will set up the 'phone' rule already defined in the
+ * glmPEAR/HTML/QuickForm/Rule directory which validates both
+ * US and Canadian phone numbers
+ *
+ * class exampleClass
+ * {
+ * $registeredRules = array('phone');
+ *
+ * // ... Rest of your class code
+ *
+ * public function configureRules()
+ * {
+ * $r = array();
+ *
+ * $r[] = array(
+ * 'element' => 'phone',
+ * 'message' => 'ERROR: Invalid number (xxx) xxx-xxxx!',
+ * 'type' => 'phone',
+ * 'format' => null,
+ * 'validation' => $this->validationType,
+ * 'reset' => false,
+ * 'force' => false
+ * );
+ *
+ * $this->setupRules($r);
+ * }
+ *
+ * // ... Rest of your class code
+ * }
+ *
+ *
+ * @return void
+ * @access protected
+ */
+ protected function registerRules()
+ {
+ if (is_array($this->registeredRules)) {
+ foreach ($this->registeredRules as $r) {
+ if (is_array($r)) {
+ call_user_func_array(array(&$this, 'registerRule'), $r);
+ } else {
+ // Don't nedd to register rules more than once
+ if (!$this->isRuleRegistered($r)) {
+ $this->registerRule($r, null, "HTML_QuickForm_Rule_$r");
+ }
+ }
+ }
+ }
+ }
+
+ // }}}
+
+ // {{{ setAutoValidateDateElements()
+
+ /**
+ * Set if we need to auto validate the Date Elements
+ *
+ * @param boolean $validate true/false to auto validate date elements
+ *
+ * @return void
+ * @access public
+ */
+ public function setAutoValidateDateElements($validate)
+ {
+ $this->autoValidateDateElements = $validate;
+ }
+
+ // }}}
+ // {{{ setFormData()
+
+ /**
+ * Sets the submitted values from the form
+ *
+ * Set these values into an internal variable so they will be accessible
+ * anywhere we need them in the form.
+ *
+ * @param array $exclude (optional) Any element names you don't want
+ * included. Since this is primarily used in
+ * emailing, this is helpful to exclude any data
+ * we don't want before the array is generated.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setFormData(array $exclude = array())
+ {
+ $values = $this->getSubmitValues();
+ foreach ($values as $k => $v) {
+ if ($this->elementExists($k)) {
+ $e =& $this->getElement($k);
+ if (!in_array($e->getName(), $exclude)) {
+ switch ($e->getType()) {
+ case 'date' :
+ list($m, $d, $y) = array_values($e->getValue());
+ // If all the date fields are empty, then don't add
+ // the output to the formData.
+ if (!(empty($m[0]) && empty($d[0]) && empty($y[0]))) {
+ $this->formData[$e->getName()]['label']
+ = $e->getLabel();
+
+ $oldDate = $e->getValue();
+ $newDate = Toolkit_Common::arrayFlatten(
+ $oldDate,
+ 0,
+ $newDate
+ );
+
+ $this->formData[$e->getName()]['element']
+ = implode(' / ', $newDate);
+ unset($oldDate, $newDate);
+ }
+ break;
+
+ case 'group':
+ $e->freeze();
+ $this->formData[$e->getName()]['label'] = $e->getLabel();
+ $this->formData[$e->getName()]['element'] = $e->toHtml();
+ break;
+
+ case 'select' :
+ $this->formData[$e->getName()]['label'] = $e->getLabel();
+
+ $values = $e->getValue();
+ foreach ($values as $v) {
+ $this->formData[$e->getName()]['element'] .= $v;
+ }
+ break;
+
+ default :
+ $this->formData[$e->getName()]['label'] = $e->getLabel();
+ $this->formData[$e->getName()]['element'] = $e->getValue();
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // }}}
+ // {{{ setupConstants()
+
+ /**
+ * Sets the form constant values
+ *
+ * @param array $constants Associative array of form constant values.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupConstants($constants)
+ {
+ $this->setConstants($constants);
+ }
+
+ // }}}
+ // {{{ setupDefaults()
+
+ /**
+ * Sets the form default values
+ *
+ * @param array $defaults Associative array of form default values.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupDefaults($defaults)
+ {
+ $this->setDefaults($defaults);
+ }
+
+ // }}}
+ // {{{ setupElements()
+
+ /**
+ * Sets up all the elements to the form
+ *
+ * Takes a multi-dimensional array of form elements and uses them
+ * to set up the form objects elements
+ *
+ * @param array $elements Multi-Dimensional array of form elements.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupElements($elements)
+ {
+ if (!is_array($elements)) {
+ return;
+ }
+ foreach ($elements as &$e) {
+ $this->prepElement($e);
+ switch ($e['type']) {
+ case 'group' :
+ if (is_array($e['group']) && !empty($e['group'])) {
+ // Special rendering for grouped elements.
+ unset($field);
+ foreach ($e['group'] as $g) {
+ $this->prepElement($g);
+ $field[] =& HTML_QuickForm::createElement(
+ $g['type'],
+ $g['name'],
+ $g['display'],
+ $g['opts'],
+ $g['att'],
+ $g['val']
+ );
+ }
+ $source =& $this->addGroup(
+ $field,
+ $e['name'],
+ $e['label'],
+ $e['seperator'],
+ $e['appendName']
+ );
+ }
+ break;
+
+ case 'elementGrid' :
+ $source =& $this->addElement(
+ $e['type'],
+ $e['name'],
+ $e['display'],
+ $e['opts'],
+ $e['att'],
+ $e['val']
+ );
+ unset($columnNames);
+
+ // Loop through the rows (r) and columns (c)
+ // to add each of the elements to our grid.
+ foreach ($e['group'] as $k => $r) {
+ unset($set, $rowTitle);
+ foreach ($r as $c) {
+ $columnNames[$c['display']] = $c['display'];
+
+ $set[] =& $this->createGridElement(
+ $c['type'],
+ $c['name'],
+ null,
+ $c['opts'],
+ $c['att']
+ );
+ }
+ $rowTitle = is_int($k) ? ' ' : $k;
+ $source->addRow($set, $rowTitle);
+ }
+
+ $source->setColumnNames($columnNames);
+ break;
+
+ default :
+ // Render all elements except groups
+ try {
+ $source =& $this->addElement(
+ $e['type'],
+ $e['name'],
+ $e['display'],
+ $e['opts'],
+ $e['att'],
+ $e['val']
+ );
+
+ if (PEAR::isError($source)) {
+ var_dump($source);
+ throw new Exception ('PEAR QuickForm Element Error');
+ }
+ } catch (HTML_QuickForm_Error $e) {
+ Toolkit_Common::dieGracefully(null, $e);
+ } catch (Exception $e) {
+ Toolkit_Common::handleError($e);
+ }
+
+ if ($e['type'] == 'advmultiselect') {
+ $source->setLabel($e['labels']);
+ }
+ if ($e['name'] == 'categories') {
+ $res = $source->loadArray($this->categories);
+ if (PEAR::isError($res)) {
+ Toolkit_Common::dieGracefully(null, $res);
+ }
+ }
+ if ($e['type'] == 'header') {
+ $this->formHeaders[$e['display']] = $e;
+ }
+
+ if ($e['name'] == 'captcha_rmv') {
+ $this->captchaAnswer =& $source;
+ }
+
+ if ($e['name'] == 'captcha_question') {
+ $this->captchaQuestion =& $source;
+ }
+ break;
+ }
+ }
+ $this->formElements = $elements;
+ }
+
+ // }}}
+ // {{{ setupFilters()
+
+ /**
+ * Sets any filters needed for the form elements when submitting
+ *
+ * @param array $filters Element filters.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupFilters($filters)
+ {
+ foreach ($filters as $f) {
+ $res = $this->applyFilter($f['element'], $f['filter']);
+
+ if (PEAR::isError($res)) {
+ Toolkit_Common::handleError($res);
+ }
+ }
+ }
+
+ // }}}
+ // {{{ setupRules()
+
+ /**
+ * Apply rules to the form
+ *
+ * 100 & 1000 char length limitations are automatically assigned to
+ * text/textarea elements to help reduce load limitations on the server.
+ * -request per Chuck in a conference call on (5/22/2009 @ 12:15pm)
+ *
+ * Applies rules that are defined in child classes to the form elements
+ * group rules can be kind of tricky, since you can't apply a rule
+ * directly to an element inside of a rule you have to define
+ * the rule inside a nest of array's and then add a group rule.
+ * the array will contain all the elements inside the group you wish
+ * to apply rules to.
+ *
+ * You can assign as many rules as you would like to individual elements,
+ * and you aren't required to make the array associative, although it is
+ * easier to see whats going on.
+ *
+ * see: http://pear.activeventure.com/package/package.html.html-quickform.html-quickform.addgrouprule.html
+ * for another example.
+ *
+ * // Define the rules for each element in the group.
+ * $num_rule = array(
+ * 'ERROR: Must contain a valid decimal number!',
+ * 'numeric'
+ * );
+ * // Collect together the rules for each element.
+ * $lat_rules = array('lat' => array($num_rule));
+ * $lon_rules = array('lon' => array($num_rule));
+ * $r[] = array(
+ * 'element' => 'latitude',
+ * 'message' => 'ERROR:',
+ * 'type' => 'group',
+ * 'format' => $lat_rules,
+ * 'validation' => $this->validationType,
+ * 'reset' => false,
+ * 'force' => false
+ * );
+ *
+ *
+ * To make a group required but not require every element in the group
+ * you can use the addGroupRule function again
+ * for example: say you have a group of checkboxes and you only only
+ * require 1 be checked. a simple group rule such as the following
+ * will handle this.
+ * N.B. notice the extra "howMany" index.
+ *
+ * $r[] = array(
+ * 'element' => 'element_name',
+ * 'message' => 'ERROR: Error to display!',
+ * 'type' => 'required',
+ * 'format' => null,
+ * 'howMany' => 1,
+ * 'validation'=> $this->validationType,
+ * 'reset' => true,
+ * 'force' => false,
+ * );
+ *
+ *
+ * @param array $rules Multi-Dimensional array of rules for form elements.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRules(array $rules = null)
+ {
+ $this->registerRules();
+ $preRegisteredRules = $this->getRegisteredRules();
+ if (is_array($this->formElements)) {
+ foreach ($this->formElements as $e) {
+ // Put length limitations on text and textarea fields
+ if ($e['type'] == 'text' && !$e['noCharLimit']) {
+ $this->addCharLimit($e['name'], 100);
+ } elseif ($e['type'] == 'textarea' && !$e['noCharLimit']) {
+ $this->addCharLimit($e['name'], 1000);
+ } elseif ($e['type'] == 'group') {
+ // We need to apply these same limitations to the
+ // text and textarea fields inside of groups
+ $r = array();
+ if (is_array($e['group'])) {
+ foreach ($e['group'] as $i) {
+ // Loop through group elements and if they are
+ // text/textarea fields then put the field into
+ // a rule array that we will assign to the group
+ if ($i['type'] == 'text' && !$i['noCharLimit']) {
+ $r[$i['name']][] = array(
+ 'ERROR: 100 characters max!',
+ 'maxlength'
+ );
+ } elseif ($i['type'] == 'textarea' && !$i['noCharLimit']) {
+ $r[$i['name']][] = array(
+ 'ERROR: 1000 characters max!',
+ 'maxlength'
+ );
+ }
+ }
+ }
+ if (!empty($r)) {
+ $this->addGroupRule($e['name'], $r);
+ }
+ }
+ if ($this->validationType == 'client') {
+ $label = $e['display'];
+ }
+ if ($e['req']) {
+ if ($e['type'] == 'group') {
+ foreach ($e['group'] as $ge) {
+ if ($ge['req']) {
+ $rule[$ge['name']][] = array(
+ 'ERROR: You must complete this field!',
+ 'required',
+ null,
+ $this->validationType);
+ }
+ }
+ $this->addGroupRule($e['name'], $rule);
+ unset($rule);
+ } elseif ($e['type'] == 'date') {
+ if (!empty($e['error'])) {
+ // Custom error message for the date element.
+ $error = $e['error'];
+ } else {
+ // Default error message for the date element.
+ $error = 'ERROR: You must enter a date!';
+ }
+ $this->addGroupRule(
+ $e['name'],
+ $error,
+ 'required',
+ 3,
+ $this->validationType
+ );
+ if ($this->autoValidateDateElements) {
+ $this->addRule(
+ $e['name'],
+ 'ERROR: Date is invalid!',
+ 'callback',
+ array(&$this, 'checkDateInput')
+ );
+ }
+ } else {
+ $this->addRule(
+ $e['name'],
+ "$label ERROR: You must complete this field!",
+ 'required',
+ null,
+ $this->validationType
+ );
+ }
+ }
+ }
+ }
+ if (is_array($rules)) {
+ foreach ($rules as $r) {
+ if (!is_array($r['element'])) {
+ $group = ($this->getElementType($r['element']) == 'group');
+ }
+ if ($group) {
+ $this->addGroupRule(
+ $r['element'],
+ $r['message'],
+ $r['type'],
+ $r['format'],
+ $r['howMany'],
+ $r['validation'],
+ $r['reset']
+ );
+ } elseif (in_array($r['type'], $preRegisteredRules)) {
+ $this->addRule(
+ $r['element'],
+ $r['message'],
+ $r['type'],
+ $r['format'],
+ $r['validation'],
+ $r['reset'],
+ $r['force']
+ );
+ }
+ }
+ }
+ }
+
+ // }}}
+ // {{{ setupRenderers()
+
+ /**
+ * Sets up renderers for form objects
+ *
+ * Uses the default form renderer to allow templates to be injected
+ * into the form object before displaying on a page. This allows
+ * changing the face of the form w/ out any backend adjustment.
+ *
+ * Files that can be created for templates are
+ *
+ * Examples:
+ * # Element.tpl
+ *
+ *
+ *
+ *
+ * *
+ *
+ *
+ *
+ *
+ *
+ * {error}
+ *
+ * {element}
+ *
+ *
+ *
+ *
+ * # Form.tpl
+ *
+ *
+ *
+ *
+ * {content}
+ *
+ *
+ *
+ *
+ *
+ * # GroupElement.tpl
+ *
+ *
+ *
+ * {element}
+ *
+ * *
+ *
+ * {label}
+ *
+ *
+ *
+ *
+ * # Group.tpl
+ *
+ *
+ *
+ * {content}
+ *
+ *
+ *
+ *
+ * # Header.tpl
+ *
+ *
+ *
+ * {header}
+ *
+ *
+ *
+ *
+ * # RequiredNote.tpl
+ *
+ * * Denotes required field
+ *
+ *
+ * @param array $groups any groups that need to be rendered
+ * via the groupElementTemplate and groupTemplate
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers(array $groups = array())
+ {
+ $renderer =& $this->defaultRenderer();
+ if (is_dir($this->template)) {
+ if ($dh = opendir($this->template)) {
+ while (($file = readdir($dh)) !== false) {
+ // Ignore current dir and parent dir.
+ if ($file != '..' && $file != '.' && $file != 'CVS') {
+ $baseName = reset(explode('.', $file));
+ // Ignores swp files.
+ if (!empty($baseName)) {
+ $method = "set{$baseName}Template";
+ $template = file_get_contents($this->template . $file);
+ if ( $method != 'setGroupTemplate'
+ && $method != 'setGroupElementTemplate'
+ ) {
+ if (method_exists($renderer, $method)) {
+ $renderer->$method($template);
+ }
+ } else {
+ // apply the templates to any defined groups
+ foreach ($groups as $k) {
+ $renderer->$method($template, $k);
+ }
+ }
+ }
+ }
+ }
+ closedir($dh);
+ }
+ }
+
+ // Set the default how the captcha's should look
+ // can be overridden in subclasses
+ if ($this->useCaptcha) {
+ $required = '*';
+ $error = ''.print_r($values, true).''; + $sql = " + UPDATE {$values['table_name']} + SET {$values['img_field_name']} = :new_img + WHERE {$values['primary_key']} = :id"; + $updateImg = $this->dbh->prepare($sql); + try { + $sql = " + SELECT * + FROM {$values['table_name']} + WHERE {$values['img_field_name']} != '' + AND {$values['img_field_name']} IS NOT NULL + AND {$values['img_field_name']} != 'ERROR' + AND {$values['img_field_name']} !~ '^is' + AND {$values['img_field_name']} !~ '^fs' + "; + $stmt = $this->dbh->prepare($sql); + $stmt->execute(); + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { + if ($row[$values['primary_key']]) { + echo '
' + . print_r( + $values['original_url'] + . '/' . $row[$values['img_field_name']], + true + ) . ''; + $newImage = $this->is->imageUpload($values['original_url']. '/' . $row[$values['img_field_name']]); + $updateImg->bindParam(":new_img", $newImage, PDO::PARAM_STR); + $updateImg->bindParam(":id", $row[$values['primary_key']], PDO::PARAM_STR); + $updateImg->execute(); + } + } + } catch(PDOException $e) { + Toolkit_Common::handleError($e); + } + } + + /** + * Short description for function + * + * Long description (if any) ... + * + * @return void + * @access public + */ + function setupElements() + { + $e[] = array( + 'type' => 'header', + 'name' => 'header_rmv', + 'display' => 'Converter' + ); + $e[] = array( + 'type' => 'text', + 'name' => 'original_url', + 'display' => 'Original Path URL without ending /' + ); + $e[] = array( + 'type' => 'text', + 'name' => 'table_name', + 'display' => 'Table Name' + ); + $e[] = array( + 'type' => 'text', + 'name' => 'img_field_name', + 'display' => 'Image Field Name' + ); + $e[] = array( + 'type' => 'text', + 'name' => 'primary_key', + 'display' => 'Primary Key' + ); + $e[] = array( + 'type' => 'submit', + 'name' => 'submit', + 'display' => 'Submit' + ); + parent::setupElements($e); + } + + /** + * Short description for function + * + * Long description (if any) ... + * + * @return void + * @access public + */ + function setupConstants() + { + } + + /** + * Short description for function + * + * Long description (if any) ... + * + * @return void + * @access public + */ + function setupDefaults() + { + } + + /** + * Short description for function + * + * Long description (if any) ... + * + * @return void + * @access public + */ + function setupRules() + { + } + + /** + * Short description for function + * + * Long description (if any) ... + * + * @return string Return description (if any) ... + * @access public + */ + function toHtml() + { + if ($this->validate()) { + if ($this->process(array(&$this, 'processData'), $this->mergeFiles)) { + $this->freeze(); + //$output = $this->successMsg; + //$output .= parent::toHTML(); + } + } else if ($this->isSubmitted()) { + $output = $this->errorMsg; + $output .= parent::toHtml(); + } else { + $output = parent::toHtml(); + } + return $output; + } +} +?> diff --git a/Toolkit/Image/Server.php b/Toolkit/Image/Server.php new file mode 100755 index 0000000..c56daca --- /dev/null +++ b/Toolkit/Image/Server.php @@ -0,0 +1,385 @@ + + * @copyright 2008 Steve Sutton + * @license Gaslight Media + * @version CVS: $Id: Server.php,v 1.19 2010/05/25 14:02:45 jamie Exp $ + * @link http://demo.gaslightmedia.com + */ + +/** + * Description for define + */ +define('IS_VALIDATE_SECRET', 'Glm0IS1secreT'); + +/** + * Description for define + */ +define('IS_SUBMIT_URL', FILE_SERVER_URL . 'submit.phtml'); + +/** + * Toolkit_Image_Server + * + * Class for implementation of the image server process Chuck has + * setup for is0.gaslightmedia.com + * Uses Curl PHP Library to upload images to the server + * + * @category Toolkit + * @package Image + * @author Steve Sutton
We sent the following XML:
$entryA total and complete failure occured."; + break; + case "PRODUCTION": + break; + } + } + if ($ss->debug == true) { + echo '
'.print_r($_REQUEST, true).''; + $label = new Toolkit_Members_Billing_MailingLabelPdf(); + $out = $label->printMailingLabels($dbh); + } else { + $mc = new Toolkit_Members_Billing_MemberLists($dbh); + $out = $filterForm->toHTML() . $mc->getMailableInvoices(); + } + return $this->getPageLayout($out); + } + + /** + * Runs admin template, list out all regions + * + * @param string $html Description of $html + * + * @return string + */ + protected function getPageLayout($html) + { + $GLOBALS['styleSheets'][] + = MEDIA_BASE_URL . 'Toolkit/Members/Billing/billing.css'; + $this->registry->controllerObject->content = $html; + $this->registry->controllerObject->topScripts + = Toolkit_Common::getScripts($GLOBALS['topScripts']); + $this->registry->controllerObject->bottomScripts + = Toolkit_Common::getScripts($GLOBALS['bottomScripts']); + $this->registry->controllerObject->styles + = Toolkit_Common::getStyleSheets($GLOBALS['styleSheets']); + $this->registry->tEngine->compile('admin.tpl'); + return $this->registry->tEngine->bufferedOutputObject( + $this->registry->controllerObject + ); + } + + /** + * Description of printInvoicesAction + * + * @return string + * @access public + */ + public function printInvoicesAction() + { + $dbh = Toolkit_Database::getInstance(); + $rt = filter_input( + INPUT_GET, + 'rt', + FILTER_SANITIZE_STRING + ); + $ac = filter_input( + INPUT_GET, + 'ac', + FILTER_SANITIZE_STRING + ); + $tab = filter_input( + INPUT_GET, + 'tab', + FILTER_SANITIZE_STRING + ); + $filterForm = new Toolkit_Members_Billing_InvoiceFilterForm( + 'filter-form', + 'post', + MEDIA_BASE_URL + . "admin/members.php?rt={$rt}&ac={$ac}&tab={$tab}" + ); + $filterForm->configureForm(); + if ($_POST['submit']) { + $inv = new Toolkit_Members_Billing_PrintInvoices(); + $ret = $inv->printInvoices($dbh); + if (!$ret) { + $out = '
Nothing to print
'; + } + } else { + $mc = new Toolkit_Members_Billing_MemberLists($dbh); + $out = $filterForm->toHTML() . $mc->getPrintableInvoices(); + } + return $this->getPageLayout($out); + } + + /** + * Description of indexAction() + * + * @return string + * @access public + */ + public function indexAction() + { + $mc = new Toolkit_Members_Billing_MemberLists( + Toolkit_Database::getInstance() + ); + $html = $mc->getOpenAccounts(); + return $this->getPageLayout($html); + } + + /** + * Description of sendEmailAction() + * + * @return string + * @access public + */ + public function sendEmailAction() + { + $dbh = Toolkit_Database::getInstance(); + $rt = filter_input( + INPUT_GET, + 'rt', + FILTER_SANITIZE_STRING + ); + $ac = filter_input( + INPUT_GET, + 'ac', + FILTER_SANITIZE_STRING + ); + $tab = filter_input( + INPUT_GET, + 'tab', + FILTER_SANITIZE_STRING + ); + $filterForm = new Toolkit_Members_Billing_InvoiceFilterForm( + 'filter-form', + 'post', + MEDIA_BASE_URL + . "admin/members.php?rt={$rt}&ac={$ac}&tab={$tab}" + ); + $filterForm->configureForm(); + if ($_POST['submit']) { + $emailInvoice = new Toolkit_Members_Billing_EmailInvoices(); + $ret = $emailInvoice->emailInvoices($dbh); + if ($ret) { + $out = 'Emails sent to members
'; + } else { + $out = 'Nothing to email
'; + } + } else { + $mc = new Toolkit_Members_Billing_MemberLists($dbh); + $out = $filterForm->toHTML() . $mc->getEmailableInvoices(); + } + return $this->getPageLayout($out); + } +} diff --git a/Toolkit/Members/Admin/ListAmenities.php b/Toolkit/Members/Admin/ListAmenities.php new file mode 100644 index 0000000..e6d48be --- /dev/null +++ b/Toolkit/Members/Admin/ListAmenities.php @@ -0,0 +1,133 @@ + + * @copyright 2009 Jamie Kahgee + * @license http://www.gaslightmedia.com Gaslightmedia + * @version CVS: $Id: ListAmenities.php,v 1.11 2010/01/26 19:46:15 jamie Exp $ + * @link http://demo.gaslightmedia.com + */ + +/** + * List the amenities available for members + * + * @category MembersDB + * @package Toolkit_Members + * @author Jamie KahgeeYour Newsletter has been setup for Processing. ' + . 'You should receive at least 2 emails at ' . FROM_MEMBER_NEWS_EMAIL + . '. One at the beginning, One at the completion of the processing ' + . 'and may receive others depending on how many emails are being Processed.' + . ' Refreshing this page will send out the same newsletter again.
'; + return $out; + } + // }}} + // {{{ setQuery() + + /** + * Sets the sql query to use in the DataGrid to get the results + * + * @param array $ids An array of member_id1s for the search sql + * + * @return void + * @access public + */ + public function setQuery(array $ids) + { + $memberIds = implode(', ', $ids); + $sql = " + SELECT member_id, process_email + FROM member + WHERE member_id IN ($memberIds) + "; + + $this->sql = $sql; + } + + // }}} +} +?> diff --git a/Toolkit/Members/Admin/MailOutForm.php b/Toolkit/Members/Admin/MailOutForm.php new file mode 100644 index 0000000..c299374 --- /dev/null +++ b/Toolkit/Members/Admin/MailOutForm.php @@ -0,0 +1,257 @@ + + * @copyright 2009 Gaslight Media + * @license http://www.gaslightmedia.com Gaslightmedia + * @version CVS: $Id: MailOutForm.php,v 1.10 2010/05/25 14:01:21 jamie Exp $ + * @link http://demo.gaslightmedia.com + */ + +/** + * Form to search the members database + * + * @category MembersDB + * @package Toolkit_Members + * @author Steve Sutton'.print_r($_REQUEST, true).'+
'.print_r($params, true).''; + } + $out = $form->toHtml() + . $reports->toHTML() + . $reports->getGrandTotals($dbh, $params); + return $this->getPageLayout($out); + } +} diff --git a/Toolkit/Members/Admin/Search.php b/Toolkit/Members/Admin/Search.php new file mode 100644 index 0000000..279e45a --- /dev/null +++ b/Toolkit/Members/Admin/Search.php @@ -0,0 +1,468 @@ + + * @copyright 2009 Jamie Kahgee + * @license http://www.gaslightmedia.com Gaslightmedia + * @version CVS: $Id: Search.php,v 1.18 2010/05/25 14:01:21 jamie Exp $ + * @link http://demo.gaslightmedia.com + */ + +/** + * Form to search the members database + * + * @category MembersDB + * @package Toolkit_Members + * @author Jamie Kahgee
Your Login Information has been sent to $email
" . + "Continue to Member Login
"; + } else { + $output = 'Email address not found.
'; + } + } elseif ($this->isSubmitted()) { + $output = $this->errorMsg; + $output .= parent::toHtml(); + } else { + $output .= parent::toHtml(); + } + + return $output; + } + + // }}} +} +?> diff --git a/Toolkit/Members/AuthContainer.php b/Toolkit/Members/AuthContainer.php new file mode 100644 index 0000000..994333a --- /dev/null +++ b/Toolkit/Members/AuthContainer.php @@ -0,0 +1,203 @@ + + * @copyright 2010 Jamie Kahgee + * @license http://www.gaslightmedia.com/ Gaslightmedia + * @version CVS: $Id: AuthContainer.php,v 1.3 2010/06/22 11:45:34 jamie Exp $ + * @link <> + * @see References to other sections (if any)... + */ + +/** + * Authentication container for members only area + * + * Custom container which allows us to utilize our PDO Singleton which + * takes advantage of schema based partitioning of our tables + * + * @category Members + * @package Toolkit_Members + * @author Jamie Kahgee
+ Did you place the barcode font into a system fonts directory
+ (/usr/share/fonts/ttf) and set the fonts directory correctly in the
+ pdf_functions.inc file?'
+ );
+ exit;
+ }
+
+ // Create new form
+ $this->glmpdfNextForm();
+
+ // Create Company Header
+ if (trim($inv['company_logo']) != '') {
+ $logo_y = 760 - $inv['company_logo_height'];
+ $logoImage = $this->glmpdfOpenImage($inv['company_logo']);
+ $this->glmpdfPlaceImage($logoImage, 5, $logo_y, .45);
+ }
+ $this->glmpdfSetFont("Helvetica-Bold", 12.0);
+ $this->glmpdfPlaceText($inv['company_name'], 20, 660, "left", 'black');
+ $this->glmpdfSetFont("Helvetica", 12.0);
+ $this->glmpdfPlaceText($inv['company_addr1'], 20, $this->glmpdfCurrentY, "left", 'black');
+ if (trim($inv['company_addr2']) != '') {
+ $this->glmpdfPlaceText($inv['company_addr2'], 20, $this->glmpdfCurrentY, "left", 'black');
+ }
+ $city_state = $inv['company_city'].', '.$inv['company_state'].' '.$inv['company_zip'];
+ $this->glmpdfPlaceText($city_state, 20, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText($inv['company_phone'], 20, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText($inv['company_email'], 20, $this->glmpdfCurrentY, "left", 'black');
+
+ // Invoice Header
+ $this->glmpdfSetFont("Helvetica-Bold", 26.0);
+ $this->glmpdfPlaceText('INVOICE', 570, 710, "right", 'black');
+ $this->glmpdfSetFont("Helvetica", 12.0);
+ $this->glmpdfPlaceText('Date:', 350, 650, "left", 'black');
+ $this->glmpdfPlaceText($inv['invoice_date'], 450, $this->glmpdfLastY, "left", 'black');
+// $this->glmpdfPlaceText('Invoice #:', 350, $this->glmpdfCurrentY, "left", 'black');
+// $this->glmpdfPlaceText($inv['invoice_number'], 450, $this->glmpdfLastY, "left", 'black');
+ $this->glmpdfPlaceText('Member Billing #:', 350, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText($inv['member_billing_no'], 450, $this->glmpdfLastY, "left", 'black');
+
+ // Member Info
+ $this->glmpdfSetFont("Helvetica-Bold", 22.0);
+ $this->glmpdfPlaceText('Bill To:', 20, 570, "left", 'black');
+ $this->glmpdfSetFont("Helvetica", 12.0);
+ $this->glmpdfPlaceText($inv['member_name'], 20, $this->glmpdfCurrentY, "left", 'black');
+ if ($inv['member_contact_name']) {
+ $this->glmpdfPlaceText($inv['member_contact_name'], 20, $this->glmpdfCurrentY, "left", 'black');
+ }
+ $this->glmpdfPlaceText($inv['member_addr1'], 20, $this->glmpdfCurrentY, "left", 'black');
+ if (trim($inv['member_addr2']) != '') {
+ $this->glmpdfPlaceText($inv['member_addr2'], 20, $this->glmpdfCurrentY, "left", 'black');
+ }
+ $city_state = $inv['member_city'].', '.$inv['member_state'].' '.$inv['member_zip'];
+ $this->glmpdfPlaceText($city_state, 20, $this->glmpdfCurrentY, "left", 'black');
+ //$this->glmpdfPlaceText($inv['member_email'], 20, $this->glmpdfCurrentY, "left", 'black');
+
+ // Items Header
+ //$this->glmpdfPlaceBox(1, 20, 470, 550, 20, 'white', 'white', 'round');
+ $this->glmpdfSetFont("Helvetica-Bold", 12.0);
+ $this->glmpdfPlaceText('Date', 30, 470, "left", 'black');
+ $this->glmpdfPlaceText('Description', 110, $this->glmpdfLastY, "left", 'black');
+ $this->glmpdfPlaceText('Amount', 490, $this->glmpdfLastY, "right", 'black');
+ $this->glmpdfPlaceText('Balance', 560, $this->glmpdfLastY, "right", 'black');
+ $this->glmpdfPlaceLine(1, 20, $this->glmpdfLastY - 3, 570, $this->glmpdfLastY - 3, 'black');
+
+ // Items
+ $this->glmpdfSetFont("Helvetica", 12.0);
+ $this->glmpdfPlaceText('', 30, $this->glmpdfLastY, "left", 'black');
+ foreach ($inv['items'] as $item) {
+ switch ($item['type']) {
+ // Type 1 - Invoice
+ case 1;
+ $this->glmpdfPlaceText($item['date'], 30, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText($item['descr'], 110, $this->glmpdfLastY, "left", 'black');
+ $this->glmpdfPlaceText($this->money($item['amount']), 490, $this->glmpdfLastY, "right", 'black');
+ $this->glmpdfPlaceText($this->money($item['balance']), 560, $this->glmpdfLastY, "right", 'black');
+ break;
+
+ // Type 2 - Payment
+ case 2:
+ $this->glmpdfPlaceText($item['date'], 30, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText('Payment - Thank You!', 110, $this->glmpdfLastY, "left", 'black');
+ $this->glmpdfPlaceText($this->money($item['amount']*-1), 490, $this->glmpdfLastY, "right", 'black');
+ $this->glmpdfPlaceText($this->money($item['balance']), 560, $this->glmpdfLastY, "right", 'black');
+ break;
+
+ }
+ }
+
+ // Terms
+ $this->glmpdfSetFont("Helvetica-Bold", 12.0);
+ $this->glmpdfPlaceText('Payment Terms', 30, 200, "left", 'black');
+ $this->glmpdfPlaceLine(1, 20, 197, 570, 197, 'black');
+ $this->glmpdfSetFont("Helvetica", 12.0);
+ $this->glmpdfPlaceText($inv['payment_terms'], 30, 180, "left", 'black');
+
+
+ // Tear-off Payment Form
+ $this->glmpdfPlaceLine(1, 20, 150, 570, 150, 'black', true, 4, 14);
+ $this->glmpdfSetFont("Helvetica", 10.0);
+ $this->glmpdfPlaceText('Please return this coupon below with your payment.', 300, 154, 'center', 'black');
+ $this->glmpdfPlaceText('Make checks payable to:', 20, 140, 'left', 'red');
+ $this->glmpdfSetFont("Helvetica", 12.0);
+
+ $this->glmpdfPlaceText($inv['company_name2'], 20, 128, "left", 'black');
+ $addr = $inv['company_addr1'];
+ if (trim($inv['company_addr2']) != '') {
+ $addr .= ', '.$inv['company_addr2'];
+ }
+ $addr .= ', '.$inv['company_city'].', '.$inv['company_state'].' '.$inv['company_zip'];
+ $this->glmpdfPlaceText($addr, 20, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText($inv['company_phone'].' - '.$inv['company_email'], 20, $this->glmpdfCurrentY, "left", 'black');
+
+ $this->glmpdfPlaceText($inv['member_name'], 20, 80, "left", 'black');
+ $this->glmpdfPlaceText($inv['member_addr1'], 20, $this->glmpdfCurrentY, "left", 'black');
+ if (trim($inv['member_addr2']) != '') {
+ $this->glmpdfPlaceText($inv['member_addr2'], 20, $this->glmpdfCurrentY, "left", 'black');
+ }
+ $city_state = $inv['member_city'].', '.$inv['member_state'].' '.$inv['member_zip'];
+ $this->glmpdfPlaceText($city_state, 20, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText($inv['member_phone'], 20, $this->glmpdfCurrentY, "left", 'black');
+ $this->glmpdfPlaceText($inv['member_email'], 20, $this->glmpdfCurrentY, "left", 'black');
+
+ $this->glmpdfSetFont("Helvetica-Bold", 12.0);
+ $this->glmpdfPlaceText('Please Pay:', 450, 80, "right", 'black');
+ $this->glmpdfPlaceText($this->money($inv['invoice_balance']), 560, $this->glmpdfLastY, "right", 'black');
+
+ $this->glmpdfSetFont("Helvetica-Bold", 12.0);
+ if (($inv['invoice_balance']-0) > 0) {
+ $this->glmpdfPlaceText('Payment Amount:', 450, 60, "right", 'black');
+ $this->glmpdfPlaceBox(1, 460, 75, 100, 20, 'black', 'white');
+ } else {
+ $this->glmpdfPlaceText('NO PAYMENT REQUIRED', 560, 60, "right", 'black');
+ }
+
+ $this->glmpdfSetFont("Helvetica", 12.0);
+ $this->glmpdfPlaceText('Member Billing #:', 450, 30, "right", 'black');
+ $this->glmpdfPlaceText($inv['member_billing_no'], 560, $this->glmpdfLastY, "right", 'black');
+
+ $barcode = $inv['member_billing_no'].'-'.$inv['invoice_number'];
+ $this->glmpdfSetFont('barcode', 40);
+ $this->glmpdfPlaceText("*$barcode*", 560, 110, 'right', 'black');
+ return $this->glmpdfEnd();
+ }
+
+ /**
+ * Format to money
+ *
+ * @param integer $value Value
+ * @param string $option Option
+ *
+ * @return string
+ * @access public
+ */
+ function money($value, $option = "")
+ {
+ // Check if the "NOPREFIX" option is specified
+ if (strstr($option, 'NOPREFIX')) {
+ $prefix = "";
+ } else {
+ $prefix = "$";
+ }
+
+ // Check if it's a negative value. If so, save that and make it positive.
+ $neg = false;
+ if ($value < 0) {
+ $neg = true;
+ $value *= -1;
+ }
+
+ // Do value sanity check
+ if (!is_numeric($value)) {
+ return $prefix . "0.00";
+ }
+
+ // Format number and add prefix
+ $r = $prefix.number_format($value, 2, ".", ",");
+
+ // Check if the value was negative.
+ if ($neg) {
+ if (strstr($option, 'NEG_PAREN')) {
+ $r = '('.$r.')';
+ } else {
+ $r = '-'.$r;
+ }
+ }
+
+ return $r;
+ }
+}
diff --git a/Toolkit/Members/Billing/Invoices.php b/Toolkit/Members/Billing/Invoices.php
new file mode 100644
index 0000000..5de9c39
--- /dev/null
+++ b/Toolkit/Members/Billing/Invoices.php
@@ -0,0 +1,439 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @link <>
+ */
+require_once GLM_APP_BASE . 'pdf/pdf_lib_8/GlmPdf.php';
+/**
+ * Toolkit_Members_Billing_Invoices
+ *
+ * @category Toolkit_Members
+ * @package Billing
+ * @author Steve Sutton Open Accounts
+ Member Name: %s '.$tArray['title'].' Closed Accounts All Accounts Accounts Needing Data Printable Invoices Emails Invoices Labels for Invoices No Records Matching pdfName: '.$pdfName.' pdf_create_pvf Error: " . PDF_get_errmsg($pdf).' pdf_open_pdi_document Error: " . PDF_get_errmsg($pdf).' pdf_open_pdi_page Error: " . PDF_get_errmsg($pdf).' pdf_get_pdi_value: width = '.$srcWidth.' pdf_get_pdi_value: height = '.$srcHeight.' PDF_begin_page_ext pdf_fit_pdi_page pdf_close_pdi_page PDF_end_page_ext PDF_delete_pvf
+ Did you place the barcode font into a system fonts directory
+ (/usr/share/fonts/ttf) and set the fonts directory correctly in the
+ pdf_functions.inc file?');
+ exit;
+ }
+
+
+
+ // Create new form
+ $glmPdf->glmpdf_next_form();
+
+ // Create Company Header
+ if (trim($inv['company_logo']) != '') {
+ $logo_y = 760 - $inv['company_logo_height'];
+ $logoImage = $glmPdf->glmpdf_open_image($inv['company_logo']);
+ $glmPdf->glmpdf_place_image($logoImage, 20, $logo_y, 1);
+ }
+ $glmPdf->glmpdf_set_font("Helvetica-Bold", 12.0);
+ $glmPdf->glmpdf_place_text($inv['company_name'], 20, 660, "left", 'black');
+ $glmPdf->glmpdf_set_font("Helvetica", 12.0);
+ $glmPdf->glmpdf_place_text($inv['company_addr1'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ if (trim($inv['company_addr2']) != '') {
+ $glmPdf->glmpdf_place_text($inv['company_addr2'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ }
+ $city_state = $inv['company_city'].', '.$inv['company_state'].' '.$inv['company_zip'];
+ $glmPdf->glmpdf_place_text($city_state, 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['company_phone'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['company_email'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+
+ // Invoice Header
+ $glmPdf->glmpdf_set_font("Helvetica-Bold", 26.0);
+ $glmPdf->glmpdf_place_text('INVOICE', 570, 710, "right", 'black');
+ $glmPdf->glmpdf_set_font("Helvetica", 12.0);
+ $glmPdf->glmpdf_place_text('Date:', 350, 650, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['invoice_date'], 450, $glmPdf->glmpdf_last_y, "left", 'black');
+ $glmPdf->glmpdf_place_text('Invoice #:', 350, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['invoice_number'], 450, $glmPdf->glmpdf_last_y, "left", 'black');
+ $glmPdf->glmpdf_place_text('Member Billing #:', 350, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_billing_no'], 450, $glmPdf->glmpdf_last_y, "left", 'black');
+
+ // Member Info
+ $glmPdf->glmpdf_set_font("Helvetica-Bold", 22.0);
+ $glmPdf->glmpdf_place_text('Bill To:', 20, 570, "left", 'black');
+ $glmPdf->glmpdf_set_font("Helvetica", 12.0);
+ $glmPdf->glmpdf_place_text($inv['member_name'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_addr1'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ if (trim($inv['member_addr2']) != '') {
+ $glmPdf->glmpdf_place_text($inv['member_addr2'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ }
+ $city_state = $inv['member_city'].', '.$inv['member_state'].' '.$inv['member_zip'];
+ $glmPdf->glmpdf_place_text($city_state, 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_phone'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_email'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+
+ // Terms
+ $glmPdf->glmpdf_place_box(1, 20, 470, 550, 20, 'gray', 'gray', 'round');
+ $glmPdf->glmpdf_set_font("Helvetica-Bold", 12.0);
+ $glmPdf->glmpdf_place_text('Payment Terms', 30, 455, "left", 'white');
+ $glmPdf->glmpdf_set_font("Helvetica", 12.0);
+ $glmPdf->glmpdf_place_text($inv['payment_terms'], 30, 430, "left", 'black');
+
+ // Items Header
+ $glmPdf->glmpdf_place_box(1, 20, 420, 550, 20, 'gray', 'gray', 'round');
+ $glmPdf->glmpdf_set_font("Helvetica-Bold", 12.0);
+ $glmPdf->glmpdf_place_text('Date', 30, 405, "left", 'white');
+ $glmPdf->glmpdf_place_text('Description', 110, $glmPdf->glmpdf_last_y, "left", 'white');
+ $glmPdf->glmpdf_place_text('Amount', 490, $glmPdf->glmpdf_last_y, "right", 'white');
+ $glmPdf->glmpdf_place_text('Balance', 560, $glmPdf->glmpdf_last_y, "right", 'white');
+
+ // Items
+ $glmPdf->glmpdf_set_font("Helvetica", 12.0);
+ $glmPdf->glmpdf_place_text('', 30, 380, "left", 'black');
+ foreach ($inv['items'] as $item) {
+ switch ($item['type']) {
+ // Type 1 - Invoice
+ case 1;
+ $glmPdf->glmpdf_place_text($item['date'], 30, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($item['descr'], 110, $glmPdf->glmpdf_last_y, "left", 'black');
+ $glmPdf->glmpdf_place_text(money($item['amount']), 490, $glmPdf->glmpdf_last_y, "right", 'black');
+ $glmPdf->glmpdf_place_text(money($item['balance']), 560, $glmPdf->glmpdf_last_y, "right", 'black');
+ break;
+
+ // Type 2 - Payment
+ case 2:
+ $glmPdf->glmpdf_place_text($item['date'], 30, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text('Payment - Thank You!', 110, $glmPdf->glmpdf_last_y, "left", 'black');
+ $glmPdf->glmpdf_place_text(money($item['amount']*-1), 490, $glmPdf->glmpdf_last_y, "right", 'black');
+ $glmPdf->glmpdf_place_text(money($item['balance']), 560, $glmPdf->glmpdf_last_y, "right", 'black');
+ break;
+
+ }
+ }
+
+
+ // Tear-off Payment Form
+ $glmPdf->glmpdf_place_line(1, 20, 150, 570, 150, 'black', true, 4, 14);
+ $glmPdf->glmpdf_set_font("Helvetica", 10.0);
+ $glmPdf->glmpdf_place_text('Please return this coupon below with your payment.', 300, 154, 'center', 'black');
+ $glmPdf->glmpdf_place_text('Make checks payable to:', 20, 140, 'left', 'red');
+ $glmPdf->glmpdf_set_font("Helvetica", 12.0);
+
+ $glmPdf->glmpdf_place_text($inv['company_name'], 20, 128, "left", 'black');
+ $addr = $inv['company_addr1'];
+ if (trim($inv['company_addr2']) != '') {
+ $addr .= ', '.$inv['company_addr2'];
+ }
+ $addr .= ', '.$inv['company_city'].', '.$inv['company_state'].' '.$inv['company_zip'];
+ $glmPdf->glmpdf_place_text($addr, 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['company_phone'].' - '.$inv['company_email'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+
+ $glmPdf->glmpdf_place_text($inv['member_name'], 20, 80, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_addr1'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ if (trim($inv['member_addr2']) != '') {
+ $glmPdf->glmpdf_place_text($inv['member_addr2'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ }
+ $city_state = $inv['member_city'].', '.$inv['member_state'].' '.$inv['member_zip'];
+ $glmPdf->glmpdf_place_text($city_state, 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_phone'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_email'], 20, $glmPdf->glmpdf_current_y, "left", 'black');
+
+ $glmPdf->glmpdf_set_font("Helvetica-Bold", 12.0);
+ $glmPdf->glmpdf_place_text('Please Pay:', 450, 80, "right", 'black');
+ $glmPdf->glmpdf_place_text(money($inv['invoice_balance']), 560, $glmPdf->glmpdf_last_y, "right", 'black');
+
+ $glmPdf->glmpdf_set_font("Helvetica-Bold", 12.0);
+ if (($inv['invoice_balance']-0) > 0) {
+ $glmPdf->glmpdf_place_text('Payment Amount:', 450, 60, "right", 'black');
+ $glmPdf->glmpdf_place_box(1, 460, 75, 100, 20, 'black', 'white');
+ } else {
+ $glmPdf->glmpdf_place_text('NO PAYMENT REQUIRED', 560, 60, "right", 'black');
+ }
+
+ $glmPdf->glmpdf_set_font("Helvetica", 12.0);
+ $glmPdf->glmpdf_place_text('Member Billing #:', 450, 30, "right", 'black');
+ $glmPdf->glmpdf_place_text($inv['member_billing_no'], 560, $glmPdf->glmpdf_last_y, "right", 'black');
+
+ $barcode = $inv['member_billing_no'].'-'.$inv['invoice_number'];
+ $glmPdf->glmpdf_set_font('barcode', 40);
+ $glmPdf->glmpdf_place_text("*$barcode*", 560, 110, 'right', 'black');
+ $glmPdf->glmpdfDrawGrid(1, 1);
+
+ // Close PDF setup and send to user's browser
+ $glmPdf->glmpdf_send_to_browser('', $inv['invoice_file_name']);
+}
diff --git a/Toolkit/Members/Billing/recreateInvoices.php b/Toolkit/Members/Billing/recreateInvoices.php
new file mode 100644
index 0000000..d874eea
--- /dev/null
+++ b/Toolkit/Members/Billing/recreateInvoices.php
@@ -0,0 +1,44 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @link <>
+ */
+require_once '../../../setup.phtml';
+
+$dbh = Toolkit_Database::getInstance();
+
+try {
+ $sql = "
+ SELECT *
+ FROM billing
+ WHERE invoice != ''";
+ $stmt = $dbh->query($sql);
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $invoice = Toolkit_Members_Billing_Factory::createDbObjectById(
+ $dbh,
+ 'Toolkit_Members_Billing_Billing',
+ $row['id']
+ );
+ //var_dump($invoice);
+ $pdf = new Toolkit_Members_Billing_InvoicePdf();
+ $pdfInvoice = $pdf->createPdfInvoice(
+ $dbh,
+ $row['member_id'],
+ $row['invoice_id'],
+ $row['account_id']
+ );
+
+ $invoice->setInvoice(base64_encode($pdfInvoice));
+ $invoice->save($dbh);
+ }
+} catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+}
+echo 'done';
\ No newline at end of file
diff --git a/Toolkit/Members/Billing/templates/editBilling.html b/Toolkit/Members/Billing/templates/editBilling.html
new file mode 100644
index 0000000..675cb4c
--- /dev/null
+++ b/Toolkit/Members/Billing/templates/editBilling.html
@@ -0,0 +1,42 @@
+
+
+ Attached is your membership invoice for {member_name:h}.
+
+ {companyName}
+ Please define the
+ MEMBER_RECORD_UPDATES_ADVISOR constant
+ in the setup file first.
+ Has updated thier business record and is now in a pending
+ state. To approve / reject thier changes you can either log
+ into your {$page->siteName} admin area or follow this
+ {$page->link}
+
+ Has updated thier business record and is now in a pending
+ state. To approve / reject thier changes you can either log
+ into your {$page->siteName} admin area or follow this
+ {$page->link}
+
+ Has updated thier business record and is now in a pending
+ state. To approve / reject thier changes you can either log
+ into your {$page->siteName} admin area or follow this
+ {$page->link}
+
+
+ {subject:h}
+
+
+
+ From {fname:h} {lname:h}
+
+ A new Event Record has been created from "Add Your Event" The record needs to be approved before changes go live. Goto Pending Records to View and Approve their changes. '.$sql.' Event Succesfully Deleted! \n";
+ $out .= "Exposure Reports - Check the statistics being compiled that include:\n";
+ $out .= " \n";
+ $out .= "Exposure Reports - Check the statistics being compiled that include:\n";
+ $out .= " Your Login Information has been sent to $email Continue to Login Email address not found. '.print_r($cData, true).'
+ Due Date: %s
+ Current Date: %s
+ Days Past Due: %s
+ ';
+ $params[] = "billing_type in (1,2)";
+ $sql = "
+ SELECT sum(amount) as sum,billing_type
+ FROM billing";
+ if (!empty($params)) {
+ $sql .= " WHERE " . implode(" AND ", $params);
+ }
+ $sql .= " GROUP BY billing_type";
+ try {
+ $stmt = $dbh->prepare($sql);
+ $stmt->execute();
+ $format = '
+
';
+ return $out;
+ }
+
+ /**
+ * Description of renderAmount()
+ *
+ * @param array $data Data array
+ *
+ * @return string Descript
+ * @access public
+ */
+ public function renderAmount($data)
+ {
+ extract($data['record']);
+ switch ($billing_type) {
+ case 1 :
+ $amount = (float)$amount;
+ break;
+ case 2 :
+ $amount = (float)-$amount;
+ break;
+ }
+ $format = "%01.2f";
+ return sprintf(
+ $format,
+ (float)$amount
+ );
+ }
+
+ /**
+ * Description of renderBillingType()
+ *
+ * @param array $data Data array
+ *
+ * @return string
+ * @access public
+ */
+ public function renderBillingType($data)
+ {
+ $billingTypes = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'billingType')
+ ->getContent();
+ extract($data['record']);
+ return $billingTypes[$billing_type];
+ }
+
+ /**
+ * Description of renderDescription()
+ *
+ * @param array $data Data array
+ *
+ * @return string
+ * @access public
+ */
+ public function renderDescription($data)
+ {
+ extract($data['record']);
+ switch ($billing_type) {
+ case 1 :
+ $urlFormat
+ = "members.php?rt=Members&ac=editMember&id=%d&invoice_id=%d"
+ . "&tab=invoices&returnPdf=1";
+ $url = sprintf(
+ $urlFormat,
+ $member_id,
+ $id
+ );
+ $format = 'Invoice: %s for %s';
+ $out = sprintf(
+ $format,
+ $url,
+ $invoice_id,
+ $transaction_date
+ );
+ break;
+ case 2 :
+ $paymentMethods = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'paymentMethod')
+ ->getContent();
+ $out = $paymentMethods[$payment_method].': '.$payment_data;
+ break;
+ case 3 :
+ $out = 'Adjustment: '.$payment_data;
+ break;
+ case 4:
+ $out = $note;
+ break;
+ }
+ return $out;
+ }
+
+ /**
+ * Description of renderMemberName()
+ *
+ * @param array $data Data array
+ *
+ * @return string
+ * @access public
+ */
+ public function renderMemberName($data)
+ {
+ extract($data['record']);
+ $urlFormat
+ = "members.php?rt=Members&ac=editMember&id=%d&tab=invoices";
+ $url = sprintf(
+ $urlFormat,
+ $member_id
+ );
+ $format = '%s';
+ return sprintf(
+ $format,
+ $url,
+ $member_name
+ );
+ }
+
+ /**
+ * Description of setQuery()
+ *
+ * @return array
+ * @access public
+ */
+ public function setQuery()
+ {
+ $params = array();
+ $sql = "
+ SELECT id,invoice_id,
+ to_char(transaction_time, 'MM/DD/YYY HH24:MI:SS') as transaction_time,
+ transaction_date,member_name,member_id,account_number,billing_type,
+ amount,balance,payment_method,payment_data,emailed,printed,paid,
+ invoice,notes
+ FROM billing";
+ if ( $_REQUEST['transaction_date_beg']['m']
+ && $_REQUEST['transaction_date_end']['m']
+ ) {
+ $startDate = implode("/", $_REQUEST['transaction_date_beg']);
+ $endDate = implode("/", $_REQUEST['transaction_date_end']);
+ $params[] = "transaction_date BETWEEN '{$startDate}' AND '{$endDate}'";
+ }
+ if ($_REQUEST['member_name']) {
+ $params[] = "member_name ilike '%{$_REQUEST['member_name']}%'";
+ }
+ if ($_REQUEST['account_number']) {
+ $params[] = "account_number = '{$_REQUEST['account_number']}'";
+ }
+ if (!empty($_REQUEST['payment_types'])) {
+ $params[] = "account_id IN (
+ SELECT id
+ FROM member_account
+ WHERE payment_type IN (" . implode(",", $_REQUEST['payment_types']) . ")
+ )";
+ }
+ if (!empty($_REQUEST['counties'])) {
+ $params[] = "member_id IN (
+ SELECT member_id
+ FROM member
+ WHERE region IN (" . implode(",", $_REQUEST['counties']) . "))";
+ }
+ if (!empty($_REQUEST['billing_types'])) {
+ $params[] = "billing_type IN (" . implode(",", $_REQUEST['billing_types']) . ")";
+ }
+ if (!empty($params)) {
+ $sql .= " WHERE " . implode(" AND ", $params);
+ }
+ parent::setQuery($sql);
+ return $params;
+ }
+
+ /**
+ * Description of toCSV()
+ *
+ * @return boolean|mixed
+ * @access protected
+ */
+ protected function toCSV()
+ {
+ $this->generateColumns(
+ array(
+ 'id' => 'Id',
+ 'invoice_id' => 'Invoice Id',
+ 'transaction_date' => 'Date',
+ 'member_name' => 'Member Name',
+ 'member_id' => 'Member Id',
+ 'account_number' => 'Account Number',
+ 'billing_type' => 'Billing Type',
+ 'amount' => 'Amount',
+ 'balance' => 'Balance',
+ 'payment_method' => 'Payment Method',
+ 'payment_data' => 'Payment Data'
+
+ )
+ );
+ try {
+ $bind = $this->bind($this->sql, $this->options, 'PDO');
+ if (PEAR::isError($bind)) {
+ return Toolkit_Common::handleError($bind);
+ } elseif (($recCount = $this->getRecordCount()) > 0) {
+ $this->setRendererOptions($this->rendererOptions);
+ $csv = $this->getOutput(
+ DATAGRID_RENDER_CSV,
+ $this->rendererOptions
+ );
+ if (PEAR::isError($gridBody)) {
+ return Toolkit_Common::handleError($gridBody);
+ }
+
+ return $csv;
+ } else {
+ return false;
+ }
+ } catch(PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+}
+
diff --git a/Toolkit/Members/Billing/ReportSearch.php b/Toolkit/Members/Billing/ReportSearch.php
new file mode 100644
index 0000000..9c68ac9
--- /dev/null
+++ b/Toolkit/Members/Billing/ReportSearch.php
@@ -0,0 +1,364 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_Billing_ReportSearch
+ *
+ * @category Toolkit_Members
+ * @package Billing
+ * @author Steve Sutton
+ ';
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $name
+ = ($row['billing_type'] == 1)
+ ? 'Invoices'
+ : 'Payments';
+ $out .= sprintf(
+ $format,
+ $name,
+ $row['sum']
+ );
+ }
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ $out .= 'Total %s:
+ %01.2f
+
',
+ 'label' => "Date Between",
+ 'appendName' => false
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'payment_types',
+ 'display' => 'Payment Types',
+ 'opts' => $paymentTypes,
+ 'att' => array('multiple' => 'multiple', 'size' => count($paymentTypes))
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'billing_types',
+ 'display' => 'Transaction Types',
+ 'opts' => $billingTypes,
+ 'att' => array('multiple' => 'multiple', 'size' => count($billingTypes))
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'counties',
+ 'display' => 'Counties',
+ 'opts' => $counties,
+ 'att' => array('multiple' => 'multiple', 'size' => 5)
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'report_type',
+ 'display' => 'Report Type',
+ 'opts' => array(
+ 'html' => 'html',
+ 'file' => 'file'
+ )
+ );
+
+ $e[] = array(
+ 'type' => 'submit',
+ 'req' => false,
+ 'name' => 'submit',
+ 'display' => 'Search'
+ );
+
+ $this->setupElements($e);
+ }
+
+ /**
+ * Description of configureForm()
+ *
+ * @return void
+ * @access public
+ */
+ public function configureForm()
+ {
+ $this->configureElements();
+ $this->configureFilters();
+ $this->configureConstants();
+ }
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function configureFilters()
+ {
+ $filters[] = array(
+ 'element' => '__ALL__',
+ 'filter' => 'trim'
+ );
+
+ $this->setupFilters($filters);
+ }
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function configureConstants()
+ {
+ $constants = array(
+ 'rt' => 'Reports',
+ 'ac' => 'searchReports'
+ );
+
+ $this->setupConstants($constants);
+ }
+
+ /**
+ * Description of getCounties()
+ *
+ * @return array
+ * @access public
+ */
+ public function getCounties()
+ {
+ $counties = array();
+ try {
+ $sql = "
+ SELECT *
+ FROM region
+ ORDER BY region_name";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->execute();
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $counties[$row['region_id']] = $row['region_name'];
+ }
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ return $counties;
+ }
+
+ /**
+ * Get all payment types for a select list
+ *
+ * @return array
+ * @access protected
+ */
+ protected function getPaymentTypes()
+ {
+ $paymentTypes = array();
+ try {
+ $sql = "
+ SELECT *
+ FROM payment_types
+ ORDER BY name";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->execute();
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $paymentTypes[$row['id']] = $row['name'] . ' ($'.$row['amount'].')';
+ }
+ return $paymentTypes;
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ /**
+ * Description of setupRenderers()
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ $renderer = new HTML_QuickForm_Renderer_Object(true);
+ $this->accept($renderer);
+ $this->template = new HTML_Template_Flexy($this->flexyOptions);
+ $this->view = $this;
+ $this->view->baseUrl = MEDIA_BASE_URL;
+ $this->view->form = $renderer->toObject();
+ $this->template->compile($this->formTemplate);
+ }
+
+ /**
+ * Description of toHTML()
+ *
+ * @return string
+ * @access public
+ */
+ public function toHTML()
+ {
+ $this->setupRenderers();
+ return $this->template->bufferedOutputObject($this->view);
+ }
+}
diff --git a/Toolkit/Members/Billing/Statement.php b/Toolkit/Members/Billing/Statement.php
new file mode 100644
index 0000000..85fa439
--- /dev/null
+++ b/Toolkit/Members/Billing/Statement.php
@@ -0,0 +1,515 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_Billing_Statement
+ *
+ * @category Toolkit_Members
+ * @package Billing
+ * @author Steve Sutton ';
+ $("#transDate").after(transImg);
+ var month = (MemberBilling.today.getMonth()) + 1;
+ var day = MemberBilling.today.getDate();
+ var year = MemberBilling.today.getFullYear();
+ var transCal = new Zapatec.Calendar.setup({
+ weekNumbers : false,
+ ifFormat : '%m/%d/%Y',
+ button : 'transDateCal',
+ onUpdate : MemberBilling.updateTransactionDateField,
+ showsTime : false,
+ range : [MemberBilling.today.getFullYear(), MemberBilling.today.getFullYear() + 1],
+ date : '7/1/' + year
+ });
+ }
+ if ($(".delete-billing").length > 0) {
+ $(".delete-billing").click(
+ function () {
+ var ret = confirm(
+ 'This action cannot be undone!\nAre you sure?'
+ );
+ return ret;
+ }
+ );
+ }
+ },
+ updateTransactionDateField: function(cal)
+ {
+ var date = cal.date;
+ var month = date.getMonth() + 1;
+ var day = date.getDate();
+ var year = date.getFullYear();
+
+ $("#transDate").val(month + '/' + day + '/' + year);
+ }
+
+}
+
+$(document).ready(MemberBilling.init);
diff --git a/Toolkit/Members/Billing/pdfInvoice.php b/Toolkit/Members/Billing/pdfInvoice.php
new file mode 100644
index 0000000..ea518f8
--- /dev/null
+++ b/Toolkit/Members/Billing/pdfInvoice.php
@@ -0,0 +1,318 @@
+
+ * @copyright 2010-2010 Gaslight Media
+ * @license http://app.gaslightmedia.com/license.php Gaslight Media
+ * @link http://www.gaslightmedia.com www.gaslightmedia.com
+ * @since $Date: 2011/03/18 12:33:47 $
+ */
+
+define('GLMPDF_DEBUG', false);
+
+// Setup border parameters
+define('BORDER_WIDTH', 0);
+define('BORDER_COLOR', 'black');
+
+// Set paper size
+define('PAPER_SIZE', 'US Letter');
+
+// Set system parameters
+define('GLM_PDF_ROOT', GLM_APP_BASE . "pdf/pdf_lib_8/");
+
+// putenv("PDFLIBSERIAL=L40300-102733-2200XX-5B12E1"); // PDFLib License Number
+
+require_once GLM_PDF_ROOT . "glmPdf.php";
+
+/**
+ * money()
+ *
+ * Format a number using conventions for money.
+ *
+ * @param float $value Value to be formatted
+ * @param string $option Comma or space separated options controlling format
+ *
+ * Options:
+ * NOPREFIX Do not prefix the number with a $.
+ * NEG_PAREN Use parenthesis instead of "-" to designate a negative number.
+ *
+ * @return string
+ * @access public
+ */
+function money($value, $option = "")
+{
+
+ // Check if the "NOPREFIX" option is specified
+ if (strstr($option, 'NOPREFIX')) {
+ $prefix = "";
+ } else {
+ $prefix = "$";
+ }
+
+ // Check if it's a negative value. If so, save that and make it positive.
+ $neg = false;
+ if ($value < 0) {
+ $neg = true;
+ $value *= -1;
+ }
+
+ // Do value sanity check
+ if (!is_numeric($value)) {
+ return( $prefix."0.00" );
+ }
+
+ // Format number and add prefix
+ $r = $prefix.number_format($value, 2, ".", ",");
+
+ // Check if the value was negative.
+ if ($neg) {
+ if (strstr($option, 'NEG_PAREN')) {
+ $r = '('.$r.')';
+ } else {
+ $r = '-'.$r;
+ }
+ }
+
+ return $r;
+}
+
+
+/**
+ * glmpdf_invoice()
+ *
+ * Create an invoice (style 1) and return as a PDF.
+ *
+ * @param array $inv An array specifying invoice contents
+ *
+ * Format of $inv. A sample follows...
+ *
+ * array(
+ * 'company_logo' => GLM_PDF_ROOT."forms/invoices/gaslight.gif",
+ * 'company_logo_height' => 70,
+ * 'comany_name_in_header' => false,
+ * 'company_name' => 'Gaslight Media',
+ * 'company_addr1' => '120 E. Lake St.',
+ * 'company_addr2' => '',
+ * 'company_city' => 'Petoskey',
+ * 'company_state' => 'MI',
+ * 'company_zip' => '49770',
+ * 'company_phone' => '231-487-0692',
+ * 'company_email' => 'info@gaslightmedia.com',
+ * 'invoice_date' => 'February 25, 2011',
+ * 'invoice_number' => '1001',
+ * 'invoice_balance' => 123.42,
+ * 'invoice_file_name' => 'invoice_1001.pdf',
+ * 'member_billing_no' => '123456',
+ * 'member_name' => 'Fred Jones Digging',
+ * 'member_addr1' => '123 E. West St.',
+ * 'member_addr2' => 'Suite 35A',
+ * 'member_city' => 'Eagle Mountain',
+ * 'member_state' => 'MI',
+ * 'member_zip' => '49110',
+ * 'member_phone' => '123-123-1234',
+ * 'member_email' => 'info@fjdig.com',
+ * 'payment_terms' => 'Payable upon receipt',
+ * 'items' => array(
+ * array(
+ * 'type' => 1, // Invoice
+ * 'date' => '01/01/2011',
+ * 'descr' => 'Yearly Member Billing',
+ * 'amount' => 123.12,
+ * 'balance' => 123.12
+ * ),
+ * array(
+ * 'type' => 2, // Payment
+ * 'date' => '01/01/2011',
+ * 'descr' => 'Check # 12345',
+ * 'amount' => 123.12,
+ * 'balance' => 0
+ * )
+ * )
+ * );
+ *
+ * @return string (pdf)
+ * @access public
+ */
+function glmpdf_invoice_1($inv)
+{
+ $glmPdf = new glmPdf();
+ /*
+ * Setup Forms Form layout
+ *
+ * x = bottom, y = left, xs = horz size, ys = vert size
+ *
+ * Invoice form is single form per page full page
+ */
+ $invoice_forms = array(
+ 1 => array( 'x' => 0, 'y' => 0, 'xs' => 612, 'ys' => 792 )
+ );
+
+ // Initialize Forms
+ $r = $glmPdf->glmpdf_set_forms(
+ count($invoice_forms),
+ $voucher_forms,
+ $glmPdf->glmpdf_standard_page[PAPER_SIZE]['x'],
+ $glmPdf->glmpdf_standard_page[PAPER_SIZE]['y']
+ );
+ if (!$r) {
+ echo "ERROR: Unable to set PDF forms layout.";
+ exit;
+ }
+
+ // Start PDF Generation - (Creator, Author, Title)
+ $glmPdf->glmpdf_start("GLM PDF", "Gaslight Media", "Standard Invoice with Payment Form");
+//var_dump($glmPdf->glmpdf_pdf);
+// exit;
+ // Load barcode font
+ if (!$glmPdf->glmpdf_add_font('barcode', 'barcode/FREE3OF9.TTF')) {
+ throw new Exception('ERROR: Unable to add barcode font.
+
+
\ No newline at end of file
diff --git a/Toolkit/Members/Billing/templates/memberStatements.html b/Toolkit/Members/Billing/templates/memberStatements.html
new file mode 100644
index 0000000..caaeecd
--- /dev/null
+++ b/Toolkit/Members/Billing/templates/memberStatements.html
@@ -0,0 +1,44 @@
+
+
\ No newline at end of file
diff --git a/Toolkit/Members/Billing/templates/paymentForm.html b/Toolkit/Members/Billing/templates/paymentForm.html
new file mode 100644
index 0000000..04eef40
--- /dev/null
+++ b/Toolkit/Members/Billing/templates/paymentForm.html
@@ -0,0 +1,39 @@
+
+
+
+
+ Member Name
+ Account Number
+ Payment Type
+ Balance Due
+
+
+
+
+ {member[member_name]:h}
+
+
+ {member[account_number]:h}
+
+
+ {member[payment_type]:h}
+
+
+ {member[balanceDue]:h}
+
+ Report Generator
+
+ {foreach:sec.elements,elem}
+ {if:elem.style}
+ {elem.outputStyle():h}
+ {else:}
+ {if:elem.isButton()}
+ {if:elem.notFrozen()}
+
+ {end:}
+ {else:}
+
+ {if:elem.error}{end:}
+ {else:}
+
+ {if:elem.required}*{end:}
+ {if:elem.error}{end:}
+ {elem.label:h}:
+ {if:elem.error}{end:}
+
+ {end:}
+ {if:elem.error}
+ {companyName2}
+ {companyAddr1}
+ {companyCity}, {companyState} {companyZip}
+ {companyPhone}
+ {companyUrl}
+
+ ";
+echo '%s
+ %s
+ %s
+ %s
+ %s
+ %s
+ ';
+$memberDat = new memberObj($dbh2);
+
+while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $matchStmt->bindParam(
+ ':member_id',
+ $row['member_id'],
+ PDO::PARAM_INT
+ );
+ $matchStmt->execute();
+ $matchData = $matchStmt->fetch();
+ if ($matchData) {
+ printf(
+ $format,
+ $row['member_id'],
+ $row['member_name'],
+ (($matchData['member_name'])
+ ? $matchData['member_name']
+ : 'Not Found'),
+ $row['type'],
+ $matchData['type'],
+ $row['account_number']
+ );
+ $dbh2->beginTransaction();
+ $updateMember->bindParam(
+ ':account_number',
+ $row['account_number'],
+ PDO::PARAM_STR
+ );
+ $updateMember->bindParam(
+ ':type',
+ $row['type'],
+ PDO::PARAM_STR
+ );
+ $updateMember->bindParam(
+ ':member_id',
+ $row['member_id'],
+ PDO::PARAM_INT
+ );
+ $updateMember->execute();
+ $dbh2->rollBack();
+ } else {
+ $notFound[] = $row;
+ $sql = $memberDat->createSQLInsert('member', array_keys($row));
+ var_dump($sql);
+ $dbh2->beginTransaction();
+ $insertStmt = $memberDat->prepareQuery($dbh2, $sql, $row);
+ $insertStmt->execute();
+ $dbh2->rollBack();
+ }
+}
+
+echo '
';
+var_dump($notFound);
diff --git a/Toolkit/Members/BreadCrumbs.php b/Toolkit/Members/BreadCrumbs.php
new file mode 100644
index 0000000..538d4a9
--- /dev/null
+++ b/Toolkit/Members/BreadCrumbs.php
@@ -0,0 +1,147 @@
+
+ * @copyright 2012 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: $id$
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_Admin_NewsletterController
+ *
+ * Description of Toolkit_Members_Admin_NewsletterController
+ *
+ * @category Toolkit
+ * @package Members_Admin
+ * @author Jamie Kahgee ";
+ return $img;
+ }
+ }
+
+ // }}}
+ // {{{ getDesc()
+
+ /**
+ * get the description of the city
+ *
+ * @return string city description
+ * @access public
+ */
+ public function getDescription()
+ {
+ return $this->description;
+ }
+
+ // }}}
+
+ // {{{ _isDuplicate()
+
+ /**
+ * get the description of the city
+ *
+ * @param integer $ignore city records to not include in count
+ *
+ * @return mixed city description, error, bool
+ * @access private
+ */
+ private function _isDuplicate($ignore = null)
+ {
+ $sql = "
+ SELECT count(*) AS total
+ FROM {$this->tableName}
+ WHERE city_name = :name
+ AND state_id = :state";
+
+ if (is_numeric($ignore)) {
+ $sql .= " AND city_id <> $ignore";
+ }
+
+ try {
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':name', $this->name, PDO::PARAM_STR);
+ $stmt->bindParam(':state', $this->state, PDO::PARAM_INT);
+ $stmt->execute();
+ $stmt->bindColumn('total', $total);
+ $stmt->fetch();
+
+ return (bool) $total;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ setName()
+
+ /**
+ * set the name of the city
+ *
+ * @param string $name City Name
+ *
+ * @return string
+ * @access public
+ */
+ public function setName($name)
+ {
+ $this->name = $name;
+ }
+
+ // }}}
+ /**
+ * Set latitude of the city
+ *
+ * @param int $lat City latitude
+ *
+ * @return void
+ * @access public
+ */
+ public function setLat($lat)
+ {
+ $newLat = (float) $lat;
+ if ($newLat >= -90.0 && $newLat <= 90.0) {
+ $this->lat = $newLat;
+ }
+ }
+
+ /**
+ * Set longitude of the city
+ *
+ * @param int $lng City longitude
+ *
+ * @return void
+ * @access public
+ */
+ public function setLon($lng)
+ {
+ $newLng = (float) $lng;
+ if ($newLng >= -180.0 && $newLng <= 180.0) {
+ $this->lon = $newLng;
+ }
+ }
+ // {{{ setState()
+
+ /**
+ * set the state the city belongs in
+ *
+ * @param integer $state state id from db
+ *
+ * @return void
+ * @access public
+ * @throws PEAR_Error
+ */
+ public function setState($state)
+ {
+ if (!is_numeric($state)) {
+ return PEAR::raiseError('Invalid state id');
+ }
+
+ $this->state = $state;
+ }
+
+ // }}}
+ // {{{ setRegion()
+
+ /**
+ * set the Region the city belongs in
+ *
+ * @param integer $region region id from db
+ *
+ * @return void
+ * @access public
+ * @throws PEAR_Error
+ */
+ public function setRegion($region)
+ {
+ if (!is_numeric($region)) {
+ return PEAR::raiseError('Invalid region id');
+ }
+ $this->region = $region;
+ }
+
+ // }}}
+ // {{{ setImage()
+
+ /**
+ * set the city image
+ *
+ * @param string $image the city image
+ *
+ * @return void
+ * @access public
+ */
+ public function setImage($image)
+ {
+ $this->image = $image;
+ }
+
+ // }}}
+ // {{{ setImageServer()
+
+ /**
+ * set the image server to use
+ *
+ * @param Toolkit_Image_Server $is Image Server Instance
+ *
+ * @return void
+ * @access public
+ */
+ public function setImageServer(Toolkit_Image_Server $is)
+ {
+ $this->is = $is;
+ }
+
+ // }}}
+ // {{{ setDesc()
+
+ /**
+ * set the description of the city
+ *
+ * @param string $desc City Description
+ *
+ * @return void
+ * @access public
+ */
+ public function setDescription($desc)
+ {
+ $this->description = $desc;
+ }
+
+ // }}}
+
+ // {{{ updateCity()
+
+ /**
+ * update a city in the DB
+ *
+ * @param integer $id record id to update
+ *
+ * @return mixed
+ * @access public
+ * @throws PEAR_Error
+ */
+ public function updateCity($id)
+ {
+ // Minimum required fields to have an array
+ if (!is_numeric($this->state) || empty($this->name)) {
+ return false;
+ }
+
+ if ($this->_isDuplicate($id)) {
+ return PEAR::raiseError('This city already exists');
+ }
+
+ $this->setLatLonCoordinates();
+
+ $values = array(
+ 'city_name' => $this->name,
+ 'state_id' => $this->state,
+ 'region_id' => $this->region,
+ 'description' => $this->description,
+ 'image' => $this->image,
+ 'lat' => $this->lat,
+ 'lon' => $this->lon
+ );
+
+ $sql = Toolkit_Common::createSQLUpdate(
+ $this->tableName,
+ array_keys($values),
+ array('city_id = :city_id')
+ );
+
+ $values['city_id'] = $id;
+
+ try {
+ return Toolkit_Common::processQuery(
+ $this->dbh,
+ $this->tableName,
+ $sql,
+ $values
+ );
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/Contact.php b/Toolkit/Members/Contact.php
new file mode 100644
index 0000000..9616e32
--- /dev/null
+++ b/Toolkit/Members/Contact.php
@@ -0,0 +1,508 @@
+
+ * @license Gaslight Media
+ * @link <>
+ */
+/**
+ * Toolkit_Members_Contact
+ *
+ * Description for Toolkit_Members_Contact
+ *
+ * @category Toolkit
+ * @package Members
+ * @author Steve Sutton
';
+ $path = THUMB;
+ $c['current_image_rmv'] = sprintf($img, $path, $currImg);
+ }
+
+ $this->setupConstants($c);
+ }
+
+ // }}}
+ // {{{ configureDefaults()
+
+ /**
+ * Configure the initial default values for the form
+ *
+ * @param PDO $dbh Database handler
+ *
+ * @return void
+ * @access protected
+ */
+ public function configureDefaults(PDO $dbh)
+ {
+ if (ctype_digit($_GET['id'])) {
+ try {
+ $sql = "
+ SELECT *
+ FROM coupons
+ WHERE id = :id";
+ $stmt = $dbh->prepare($sql);
+ $stmt->bindParam(":id", $_GET['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ $d = $stmt->fetch(PDO::FETCH_ASSOC);
+ if ($d['image']) {
+ $d['current_image_rmv'] = '
';
+ } else {
+ $d['current_image_rmv'] = 'Nothing uploaded yet';
+ }
+ //echo ''.print_r($d, true).'
';
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ //die('fix configure defaults');
+ } else {
+ $date = new Date();
+ $sdateMonth = $date->getMonth();
+ $sdateDay = $date->getDay();
+ $sdateYear = $date->getYear();
+
+ $date->addMonths(6);
+
+ $edateMonth = $date->getMonth();
+ $edateDay = $date->getDay();
+ $edateYear = $date->getYear();
+ $d = array(
+ 'sdate' => array(
+ 'm' => $sdateMonth,
+ 'd' => $sdateDay,
+ 'Y' => $sdateYear
+ ),
+ 'edate' => array(
+ 'm' => $edateMonth,
+ 'd' => $edateDay,
+ 'Y' => $edateYear
+ ),
+ 'expiration' => array(
+ 'm' => $edateMonth,
+ 'd' => $edateDay,
+ 'Y' => $edateYear
+ ),
+ );
+ }
+
+ $this->setupDefaults($d);
+ }
+
+ // }}}
+ // {{{ configureElements()
+
+ /**
+ * Configure how the form elements should look
+ *
+ * @param PDO $dbh Database handler
+ * @param Config_Container $c Configuration object
+ *
+ * @return void
+ * @access public
+ */
+ public function configureElements(PDO $dbh, Config_Container $c)
+ {
+ $e = array();
+
+ $categories = $this->_getCategories($dbh);
+
+ // Get reference to [conf] section of config file
+ $conf =& $c->getItem('section', 'conf');
+
+ $minYear = $c->getItem('section', 'conf')
+ ->getItem('directive', 'dateStartYear')
+ ->getContent();
+
+ // All Grouped Elements are created here.
+
+ // All Elements are created here. This includes group element definitions.
+ $e[] = array(
+ 'type' => 'html',
+ 'req' => false,
+ 'name' => ' ',
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'active',
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'pending',
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'member',
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => true,
+ 'name' => 'category',
+ 'display' => 'Category',
+ 'opts' => array('' => '-- Select --') + $categories
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => true,
+ 'name' => 'title',
+ 'display' => 'Title',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'textarea',
+ 'req' => false,
+ 'name' => 'description',
+ 'display' => 'Description 600 characters left',
+ 'opts' => array('id' => 'description')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'url',
+ 'display' => 'Website Link',
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'current_image_rmv',
+ 'display' => 'Current Coupon Image'
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'image'
+ );
+ $e[] = array(
+ 'type' => 'file',
+ 'req' => false,
+ 'name' => 'file_rmv',
+ 'display' => 'New Coupon Image'
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'img_instructions_rmv',
+ 'opts' => '.jpg or .gif images only'
+ );
+ $e[] = array(
+ 'type' => 'date',
+ 'req' => true,
+ 'name' => 'sdate',
+ 'display' => 'Start Date',
+ 'opts' => array(
+ 'format' => 'm / d / Y',
+ 'minYear' => $minYear,
+ 'maxYear' => date('Y') + 5,
+ 'addEmptyOption' => true,
+ 'emptyOptionText' => array(
+ 'm' => 'mm',
+ 'd' => 'dd',
+ 'Y' => 'yyyy'
+ )
+ ),
+ 'att' => array('id' => 'sdate')
+ );
+ $e[] = array(
+ 'type' => 'date',
+ 'req' => true,
+ 'name' => 'edate',
+ 'display' => 'End Date',
+ 'opts' => array(
+ 'format' => 'm / d / Y',
+ 'minYear' => $minYear,
+ 'maxYear' => date('Y') + 5,
+ 'addEmptyOption' => true,
+ 'emptyOptionText' => array(
+ 'm' => 'mm',
+ 'd' => 'dd',
+ 'Y' => 'yyyy'
+ )
+ ),
+ 'att' => array('id' => 'edate')
+ );
+ $e[] = array(
+ 'type' => 'date',
+ 'req' => true,
+ 'name' => 'expiration',
+ 'display' => 'Expire Date',
+ 'opts' => array(
+ 'format' => 'm / d / Y',
+ 'minYear' => $minYear,
+ 'maxYear' => date('Y') + 5,
+ 'addEmptyOption' => true,
+ 'emptyOptionText' => array(
+ 'm' => 'mm',
+ 'd' => 'dd',
+ 'Y' => 'yyyy'
+ )
+ ),
+ 'att' => array('id' => 'expire')
+ );
+ $e[] = array(
+ 'type' => 'submit',
+ 'req' => false,
+ 'name' => 'submit_rmv',
+ 'display' => 'Submit Coupon',
+ 'opts' => array('id' => 'submit')
+ );
+ if (ctype_digit($_GET['id'])) {
+ $e[] = array(
+ 'type' => 'submit',
+ 'req' => false,
+ 'name' => 'delete_rmv',
+ 'display' => 'Delete Coupon',
+ 'opts' => array(
+ 'id' => 'delete',
+ 'onClick' => 'return confirm(\'This will delete the Coupon\nAre You Sure?\');'
+ )
+ );
+ }
+
+ $this->setupElements($e);
+ }
+
+ // }}}
+ // {{{ configureFilters()
+
+ /**
+ * Configure how the form elements should act when being submitted
+ *
+ * @return void
+ * @access protected
+ */
+ public function configureFilters()
+ {
+ $f = array();
+ $f[] = array(
+ 'element' => '__ALL__',
+ 'filter' => 'trim'
+ );
+ $f[] = array(
+ 'element' => 'url',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+
+ $this->setupFilters($f);
+ }
+
+ // }}}
+ // {{{ configureForm()
+
+ /**
+ * Configure a form so we can use it
+ *
+ * @param PDO $dbh Database handler
+ * @param Config_Container $c Application configuration settings
+ *
+ * @return void
+ * @access public
+ */
+ public function configureForm(
+ PDO $dbh,
+ Config_Container $c
+ ) {
+ $this->configureElements($dbh, $c);
+ $this->configureFilters();
+ $this->configureRules();
+ $this->configureDefaults($dbh);
+ $this->configureConstants();
+ }
+
+ // }}}
+ // {{{ configureRules()
+
+ /**
+ * Configure how the form elements should act
+ *
+ * @return void
+ * @access public
+ */
+ public function configureRules()
+ {
+ $r = array();
+
+ $mimeTypes = array(
+ 'image/jpe',
+ 'image/jpeg',
+ 'image/jpg',
+ 'image/jfif',
+ 'image/pjpeg',
+ 'image/pjp',
+ 'image/gif',
+ 'image/png',
+ );
+
+ $r[] = array(
+ 'element' => 'url',
+ 'message' => 'ERROR: Invalid URL format (http, https only)',
+ 'type' => 'checkURI',
+ 'format' => array(
+ 'allowed_schemes' => array('http', 'https'),
+ 'strict' => true
+ ),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'sdate',
+ 'message' => 'ERROR: Invalid Date!',
+ 'type' => 'Date',
+ 'format' => array('format' => '%m-%d-%Y'),
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'edate',
+ 'message' => 'ERROR: Invalid Date!',
+ 'type' => 'Date',
+ 'format' => array('format' => '%m-%d-%Y', 'allowEmpty' => true),
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'expire',
+ 'message' => 'ERROR: Invalid Date!',
+ 'type' => 'Date',
+ 'format' => array('format' => '%m-%d-%Y', 'allowEmpty' => true),
+ 'validation' => $this->validationType,
+ 'reset' => true,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => array('sdate', 'edate'),
+ 'message' => 'ERROR: Invalid Start Date!',
+ 'type' => 'callback',
+ 'format' => array(&$this, 'checkDates'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => array('edate', 'expire'),
+ 'message' => 'ERROR: Expire date ends before end date!',
+ 'type' => 'callback',
+ 'format' => array(&$this, 'checkDates'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ if (is_uploaded_file($_FILES['file_rmv']['tmp_name'])) {
+ $r[] = array(
+ 'element' => 'file_rmv',
+ 'message' => 'ERROR: Incorrect File Type (.gif, .png, .jpg) only!',
+ 'type' => 'mimetype',
+ 'format' => $mimeTypes,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ }
+
+ $this->setupRules($r);
+ }
+
+ // }}}
+
+ // {{{ _getCategories()
+
+ /**
+ * Get the array of coupon categories used for the select list
+ *
+ * @param PDO $dbh Database handler
+ *
+ * @return array categories used to populate a select list element
+ * @access protected
+ */
+ private function _getCategories(PDO $dbh)
+ {
+ // Get only the active categories from
+ // the nav structure for our select list.
+ $sql = "
+ SELECT *
+ FROM coupon_category
+ ORDER BY name";
+
+ $categories = array();
+ foreach ($dbh->query($sql, PDO::FETCH_ASSOC) as $row) {
+ $categories[$row['name']] = $row['name'];
+ }
+ return $categories;
+ }
+
+ // }}}
+
+ // {{{ _processData()
+
+ /**
+ * Determine how the form should be handled (insert new data or update old)
+ *
+ * @param PDO $dbh Database handler
+ * @param array $values Submitted form values
+ * @param Toolkit_Coupons_CouponFactory $cFactory Coupon
+ * @param stdClass &$couponMailerTemplateData Coupon mailer template data
+ *
+ * @return boolean Result of insert or update function
+ * @access private
+ */
+ private function _processData(
+ PDO $dbh,
+ array $values,
+ Toolkit_Coupons_CouponFactory $cFactory,
+ stdClass &$couponMailerTemplateData
+ ) {
+ unset($values['MAX_FILE_SIZE']);
+
+ $deleteImage = ($_POST['del_image_rmv']) ? true: false;
+ foreach ($values as $k => $v) {
+ if ( $k != 'uploaded_file_rmv'
+ && preg_match('/^.+_rmv$/', $k)
+ ) {
+ unset($values[$k]);
+ }
+ }
+
+ $sdateStr = implode('/', $values['sdate']);
+ $sdateTS = strtotime($sdateStr);
+ $sdate = new Date();
+ $sdate->setDate($sdateTS, DATE_FORMAT_TIMESTAMP);
+ $values['sdate'] = $sdate;
+
+ $edateStr = implode('/', $values['edate']);
+ $edateTS = strtotime($edateStr);
+ $edate = new Date();
+ $edate->setDate($edateTS, DATE_FORMAT_TIMESTAMP);
+ $values['edate'] = $edate;
+
+ $exdateStr = implode('/', $values['expiration']);
+ $exdateTS = strtotime($exdateStr);
+ $exdate = new Date();
+ $exdate->setDate($exdateTS, DATE_FORMAT_TIMESTAMP);
+ $values['expiration'] = $exdate;
+ if ($deleteImage) {
+ $values['image'] = null;
+ } else {
+ $values['image'] = Toolkit_Coupons_ImageFactory::getImage($values);
+ }
+ $values['member'] = $_SESSION['_authsession']['data']['member_id'];
+ $values['active'] = 0;
+ if (ctype_digit((string)$_GET['id'])) {
+ // Editing a banner
+ $coupon =& $cFactory->fetch($dbh, $_GET['id']);
+ } else {
+ $coupon =& $cFactory->createCoupon($values);
+ }
+
+ if (filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT)) {
+ $coupon->setPending(true);
+ $res = $coupon->update($dbh, $values);
+ } else {
+ $res = $coupon->save($dbh);
+ }
+ $couponMailerTemplateData->couponId = $coupon->getId();
+
+ return $res;
+ }
+
+ // }}}
+
+ // {{{ sendCouponToImageServer()
+
+ /**
+ * Send a coupon image to the image server
+ *
+ * Sets the image name in the submit values, so when saving
+ * the banner, we keep the image that was uploaded.
+ *
+ * Injects the thumbnail image of this uploaded coupon into
+ * the form, this way if validation fails, the thumbnail will
+ * be shown on the form so the user knows they don't have to
+ * re-upload the coupon.
+ *
+ * @param Toolkit_Image_Server $is Image server
+ * @param string $file key of upload in $_FILES super array
+ *
+ * @return void
+ * @access protected
+ */
+ protected function sendCouponToImageServer(
+ Toolkit_Image_Server $is,
+ $file
+ ) {
+ $oldCoupon =& $this->getSubmitValue('image');
+ if (!empty($oldCoupon)) {
+ $is->imageDelete($oldCoupon);
+ }
+
+ $imgTag = 'Creating a Coupon:The Start date is when you expect the coupon to appear on our website. The End date is when it will automatically be removed from display to visitors. The expiration date is printed with the coupon, so be sure to set your expiration date correctly. ';
+ $name = $is->imageUpload($file);
+
+ $htmlImg = sprintf($imgTag, COUPON_THUMB, $name);
+
+ $currImg =& $this->getElement('current_image_rmv');
+ $currImg->setValue($htmlImg);
+
+ $fileName =& $this->getElement('image');
+ $fileName->setValue($name);
+ $this->_submitValues['image'] = $name;
+ }
+
+ // }}}
+ // {{{ setupRenderers()
+ // @codeCoverageIgnoreStart
+
+ /**
+ * Custom rendering templates for special fields on the form
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ parent::setupRenderers();
+ $renderer =& $this->defaultRenderer();
+ $required
+ = "\n
+ * \n
+ ";
+ $error
+ = "\n
+
\n
+ ",
+ 'description'
+ );
+ $renderer->setElementTemplate(
+ "$required{label}$error{element} \n
+ \n
+ ",
+ 'submit_rmv'
+ );
+ $renderer->setElementTemplate(
+ "$required{label}$error{element} \n
+ \n
+ ",
+ 'delete_rmv'
+ );
+
+ }
+
+ // @codeCoverageIgnoreEnd
+ // }}}
+
+ // {{{ toHtml()
+
+ /**
+ * Call the rendering function to get the form in a string
+ *
+ * @param PDO $dbh Database handler
+ * @param Toolkit_Image_Server $is Image Server
+ * @param Toolkit_Coupons_CouponFactory $cFactory Coupon
+ * @param Toolkit_Members_Coupons_Mailer $mailer Mailer
+ * @param stdClass &$couponMailerTemplateData Coupon mailer template data
+ *
+ * @return string $output The Form to be rendered or success msg.
+ * @access protected
+ */
+ public function toHtml(
+ PDO $dbh,
+ Toolkit_Image_Server $is,
+ Toolkit_Coupons_CouponFactory $cFactory,
+ Toolkit_Members_Coupons_Mailer $mailer,
+ stdClass &$couponMailerTemplateData
+ ) {
+ //$GLOBALS['styleSheets'][] = MEDIA_BASE_URL . 'css/contactform.css';
+ $GLOBALS['bottomScripts'][] = MEDIA_APP_BASE_URL . 'libjs/textlimit.js';
+ $GLOBALS['bottomScripts'][] = MEDIA_BASE_URL . 'libjs/couponLimitText.js';
+
+ // Handle Deleting coupon.
+ if ( $this->isSubmitted()
+ && ctype_digit($_GET['id'])
+ ) {
+ if ($this->getSubmitValue('delete_rmv')) {
+ $coupon = $cFactory->fetch($dbh, $_GET['id']);
+ if ($coupon instanceof Toolkit_Coupons_Coupon) {
+ if ($coupon->delete($dbh, $is)) {
+ return 'Coupon successfully deleted.';
+ }
+ } else {
+ // the coupon has already been deleted or doesn't exist.
+ return "The coupon has already been deleted or doesn't exists.";
+ }
+ }
+ }
+
+ $this->setupRenderers();
+ $uploadedNewCouponImg
+ = ( $this->isSubmitted()
+ && is_uploaded_file($_FILES['file_rmv']['tmp_name'])
+ );
+ if ($_POST['del_image_rmv'] && $_POST['old_image_rmv']) {
+ $is->imageDelete($_POST['old_image_rmv']);
+ }
+ if ($uploadedNewCouponImg) {
+ $this->sendCouponToImageServer($is, 'file_rmv');
+ }
+ if ($this->validate()) {
+ $this->cleanForm();
+
+ $submitValues = $this->getSubmitValues();
+ if ($this->_processData(
+ $dbh,
+ $submitValues,
+ $cFactory,
+ $couponMailerTemplateData
+ )
+ ) {
+ if ('' != MEMBERS_COUPON_NOTIFICATION_EMAIL) {
+ $mailer->sendNotification(
+ array(MEMBERS_COUPON_NOTIFICATION_EMAIL),
+ $couponMailerTemplateData
+ );
+ }
+ $this->freeze();
+ $output = $this->successMsg;
+ }
+ } elseif ($this->isSubmitted()) {
+ $output = $this->errorMsg;
+ $output .= parent::toHTML();
+ } else {
+ $output = parent::toHTML();
+ }
+ return $output;
+ }
+
+ // }}}
+}
diff --git a/Toolkit/Members/Coupons/Mailer.php b/Toolkit/Members/Coupons/Mailer.php
new file mode 100644
index 0000000..2621a33
--- /dev/null
+++ b/Toolkit/Members/Coupons/Mailer.php
@@ -0,0 +1,129 @@
+
+ * @copyright 2010 Jamie Kahgee
+ * @license http://www.gaslightmedia.com/ Gaslightmedia
+ * @version CVS: $Id:$
+ * @link <>
+ * @see References to other sections (if any)...
+ */
+
+/**
+ * Updated member coupon notification mailer
+ *
+ * @category Members
+ * @package Toolkit_Members
+ * @author Jamie Kahgee $required{label}$error{element} \n
+ ';
+ }
+
+ // }}}
+ // {{{ getMemberContacts()
+
+ /**
+ * Get all the contacts data uploaded to a member into an array
+ *
+ * @return array member contacts
+ * @access protected
+ */
+ protected function getMemberContacts()
+ {
+ $c = array();
+ try {
+ $sql = "
+ SELECT *
+ FROM {$this->tableName}
+ WHERE member_id = :id
+ ORDER BY id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
+ $stmt->execute();
+
+ while ($row = $stmt->fetch()) {
+ $c[] = $row;
+ }
+ return $c;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ insertData()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ *
+ * @return object Return description (if any) ...
+ * @access public
+ */
+ public function insertData($values)
+ {
+ unset(
+ $values['id'],
+ $values['target'],
+ $values['submit']
+ );
+ $values['member_id'] = $_GET['id'];
+ try {
+ $params = implode(', ', array_keys($values));
+ $bindParams = ':' . implode(', :', array_keys($values));
+ $sql = "
+ INSERT INTO {$this->tableName} ($params)
+ VALUES ($bindParams)";
+ $stmt = $this->dbh->prepare($sql);
+ foreach ($values as $k => $v) {
+ $metaData = $this->tableMetaData[$k];
+ if ($metaData == 'integer') {
+ $dataType = PDO::PARAM_INT;
+ } else if ($metaData == 'boolean') {
+ $dataType = PDO::PARAM_BOOL;
+ } elseif ($metaData == 'double precision') {
+ $dataType = null;
+ } else {
+ $dataType = PDO::PARAM_STR;
+ }
+ $stmt->bindParam(":$k", $values[$k], $dataType);
+ }
+ return $stmt->execute();
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ isForm()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $sec Parameter description (if any) ...
+ *
+ * @return unknown Return description (if any) ...
+ * @access public
+ */
+ public function isForm($sec)
+ {
+ return !$sec;
+ }
+
+ // }}}
+ // {{{ isName()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isName($name)
+ {
+ return (substr($name, 0, 4) == 'name');
+ }
+
+ // }}}
+ // {{{ isPhone()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isPhone($name)
+ {
+ return (substr($name, 0, 5) == 'phone');
+ }
+
+ // }}}
+ // {{{ isEmail()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isEmail($name)
+ {
+ return (substr($name, 0, 5) == 'email');
+ }
+
+ // }}}
+ // {{{ isTitle()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isTitle($name)
+ {
+ return (substr($name, 0, 5) == 'title');
+ }
+
+ // }}}
+
+ // {{{ processData()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ *
+ * @return void
+ * @access public
+ */
+ public function processData($values)
+ {
+ $this->tableMetaData = Toolkit_Common::getTableMetaData(
+ $this->dbh,
+ $this->tableName
+ );
+ if (empty($values['id'])) {
+ $this->insertData($values);
+ } else {
+ $this->updateData($values);
+ }
+ $listPage = MEDIA_BASE_URL .
+ "admin/members.php?page=editMember&module=addMember&tab=contacts&id={$_GET['id']}";
+ header("Location: $listPage");
+ }
+
+ // }}}
+
+ // {{{ removeContact()
+
+ /**
+ * Remove a contact from a member record
+ *
+ * @param integer $cid contact id
+ * @param integer $mid member id
+ *
+ * @return void
+ * @access public
+ */
+ public function removeContact($cid, $mid)
+ {
+ try {
+ $sql = "
+ DELETE FROM {$this->tableName}
+ WHERE id = :cid
+ AND member_id = :mid";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':cid', $cid, PDO::PARAM_INT);
+ $stmt->bindParam(':mid', $mid, PDO::PARAM_INT);
+ $stmt->execute();
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ show()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access public
+ */
+ public function show()
+ {
+ if (isset($_GET['d'])) {
+ $this->removeContact($_GET['cid']);
+ $target = MEDIA_BASE_URL . 'admin/members.php?page=editMember&module=addMember&tab=contacts&id=';
+ $target .= $_GET['id'];
+ header("Location: $target");
+ }
+ Toolkit_Common::show();
+ }
+
+ // }}}
+
+ // {{{ updateData()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ *
+ * @return boolean Return description (if any) ...
+ * @access public
+ */
+ public function updateData($values)
+ {
+ if (array_key_exists('delete', $values)) {
+ $this->deleteFile($values);
+ }
+
+ unset(
+ $values['target'],
+ $values['submit']
+ );
+
+ try {
+ $params = array_keys($values);
+ $length = count($params);
+ for ($i = 0; $i < $length; ++$i) {
+ $bindParams .= "{$params[$i]} = :{$params[$i]}";
+ if ($i < ($length - 1)) {
+ $bindParams .= ', ';
+ }
+ }
+ $sql = "
+ UPDATE {$this->tableName}
+ SET $bindParams
+ WHERE id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $pid, PDO::PARAM_INT);
+ foreach ($values as $k => $v) {
+ $metaData = $this->tableMetaData[$k];
+ if ($metaData == 'integer') {
+ $dataType = PDO::PARAM_INT;
+ } else if ($metaData == 'boolean') {
+ $dataType = PDO::PARAM_BOOL;
+ } else {
+ $dataType = PDO::PARAM_STR;
+ }
+ $stmt->bindParam(":$k", $values[$k], $dataType);
+ }
+ $stmt->execute();
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ return false;
+ }
+ return true;
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/EditMemberFile.php b/Toolkit/Members/EditMemberFile.php
new file mode 100644
index 0000000..5bb1f36
--- /dev/null
+++ b/Toolkit/Members/EditMemberFile.php
@@ -0,0 +1,558 @@
+
+ * @author Jamie Kahgee
';
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $defaults["file$i"] = $row['id'];
+ $defaults["file_name$i"] = (empty($row['file_name'])) ?
+ $row['original_name'] : $row['file_name'];
+
+ $oname = (empty($row['file_name'])) ?
+ $row['original_name'] : $row['file_name'];
+ $defaults["original_name$i"] = '
row, so they can easily
+ * be identified.
+ *
+ * @var string
+ * @access public
+ */
+ public $pendingFields = array();
+
+ // What are the modules associated with this form.
+ // New members won't have access to these right away.
+ // This boolean settings will be overridden inside the class.
+
+ /**
+ * The status of accommodation related categories associated w/ the member
+ *
+ * If the member has any categories that are assigned to the accommodations
+ * module, then this setting will become true and the form will show
+ * the accommodation module.
+ *
+ * @var bool
+ * @access protected
+ */
+ protected $accommodations = false;
+
+ /**
+ * The status of restaurant related categories associated w/ the member
+ *
+ * If the member has any categories that are assigned to the restaurant
+ * module, then this setting will become true and the form will show
+ * the restaurant module.
+ *
+ * @var bool
+ * @access protected
+ */
+ protected $restaurant = false;
+
+ /**
+ * The status of golf related categories associated w/ the member
+ *
+ * If the member has any categories that are assigned to the golf
+ * module, then this setting will become true and the form will show
+ * the golf module.
+ *
+ * @var bool
+ * @access protected
+ */
+ protected $golf = false;
+
+ /**
+ * Cities array for select list
+ *
+ * @var array
+ * @access protected
+ */
+ protected $cities;
+
+ /**
+ * States array for select list
+ *
+ * @var array
+ * @access protected
+ */
+ protected $states;
+
+ /**
+ * Category record objects
+ *
+ * Used when creating the category select list.
+ *
+ * @var array
+ * @access protected
+ */
+ protected $records = array();
+
+ /**
+ * The categories the member has associated with it
+ *
+ * @var array
+ * @access protected
+ */
+ protected $memberCategories = null;
+
+ /**
+ * Primary email address to send notification a record has been updated
+ *
+ * Set this value to false and it will turn off the email
+ * update notifications.
+ *
+ * @var string
+ * @access protected
+ */
+ protected $primaryAdvisee;
+
+ /**
+ * Email address of people that might also want to be advised of updates
+ *
+ * A list of all email address that might also want to be advised
+ * updates have been made on a business record. You can add as many
+ * as you would like and they will be CC in the email.
+ *
+ * N.B. You cannot make this array bigger than 5 people or you will need to
+ * rewrite the function to handle the server spam issue.
+ * @var array
+ * @access private
+ */
+ protected $secondaryAdvisees = array();
+
+ /**
+ * Flexy options used in the renderer
+ *
+ * @var array
+ * @access protected
+ */
+ protected $flexyOptions;
+
+ /**
+ * The name of the template used to render the business info form
+ *
+ * @var string
+ * @access protected
+ */
+ protected $formTemplate = 'editMember.tpl';
+
+ /**
+ * The name of the template used to email the owner for any updates
+ *
+ * When a member makes an update to thier record, this is the template
+ * we will use to send out the email notification to the site owner.
+ *
+ * @var string
+ * @access protected
+ */
+ protected $emailTemplate = 'emailOwner.tpl';
+
+ /**
+ * Message to return if the form successfully submits
+ *
+ * @var string
+ * @access protected
+ */
+ protected $successMsg = '
+
';
+ echo '
+
This Constant should hold
+ the email address of the person you would like notified
+ when a member submits an update.
Set to false if you do
+ not want an email to be sent.
+ ';
+ }
+ $defaults[$k] = $v;
+ }
+ }
+
+ // Set the defaults for the credit cards.
+ $sql = "
+ SELECT cct.*, mcct.*
+ FROM ccard_type cct, member_ccard_type mcct
+ WHERE cct.ccard_type_id = mcct.ccard_type_id
+ AND mcct.member_id = :member_id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $member_id, PDO::PARAM_INT);
+ $stmt->execute();
+ while ($member = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $defaults["creditCards[{$member['ccard_type_name']}]"] = true;
+ }
+
+ $moduleTables = array(
+ 'member_accommodations',
+ 'member_golf',
+ 'member_restaurants',
+ );
+ foreach ($moduleTables as $table) {
+ $sql = "
+ SELECT *
+ FROM $table
+ WHERE member_id = :member_id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $member_id, PDO::PARAM_INT);
+ $stmt->execute();
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ foreach ($row as $k => $v) {
+ $defaults[$k] = $v;
+ }
+ }
+ }
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ } else {
+ // get member type
+ $defaultState = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'defaultState')
+ ->getContent();
+ $defaults = array(
+ 'member_cats[]' => '',
+ 'state_id' => $defaultState,
+ 'country' => '',
+ );
+ }
+
+ $this->setupDefaults($defaults);
+ return $defaults;
+ }
+
+ // }}}
+ // {{{ configureElements()
+
+ /**
+ * Setup the elements to use on the form.
+ *
+ * Categories are populated into the protected class property $categories.
+ * These categories are used to populate the select list of categories.
+ * Modules are configured before any elements are setup, that way we will
+ * know if we need to include them in the rendering of the form.
+ *
+ * @return void
+ * @access public
+ */
+ public function configureElements()
+ {
+ $e = array();
+
+ // get member type
+ $singularType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'singular')
+ ->getContent();
+ $pluralType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'plural')
+ ->getContent();
+ $useCtrlCities = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'controlledCities')
+ ->getContent();
+ $allowRegions = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'regions')
+ ->getContent();
+ $dateStartYear = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'dateStartYear')
+ ->getContent();
+ $usesGlmReservations = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'glmReservations')
+ ->getContent();
+ $nonMembers = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'nonMembers')
+ ->getContent();
+
+ $this->setupFormCategories();
+ $this->configureModules();
+
+ $this->getCategories();
+
+ // All Grouped Elements are created here.
+ // All Elements are created here. This includes group element definitions.
+
+ // {{{ Member Information
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'memberInfoHdr',
+ 'display' => "$singularType Information",
+ 'col1' => true
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => true,
+ 'name' => 'active',
+ 'display' => 'Status',
+ 'opts' => 'Active',
+ 'val' => array(0, 1),
+ );
+ if ($nonMembers) {
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => true,
+ 'name' => 'non_member',
+ 'display' => 'Member?',
+ 'opts' => 'Non Member',
+ 'val' => array(0, 1),
+ );
+ }
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => true,
+ 'name' => 'member_name',
+ 'display' => "$singularType Name",
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'primary_contact_fname',
+ 'display' => 'Primary Contact First Name',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'primary_contact_lname',
+ 'display' => 'Primary Contact Last Name',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'process_email',
+ 'display' => 'Primary Contact Email',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'date',
+ 'req' => false,
+ 'name' => 'join_date',
+ 'display' => "$singularType Since",
+ 'opts' => array(
+ 'format' => 'm / d / Y',
+ 'minYear' => $dateStartYear,
+ 'maxYear' => date('Y'),
+ 'addEmptyOption' => true,
+ 'emptyOptionValue' => '',
+ 'emptyOptionText' => array(
+ 'm' => 'mm',
+ 'd' => 'dd',
+ 'Y' => 'yyyy',
+ )
+ )
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'phone',
+ 'display' => 'Primary Phone',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'toll_free',
+ 'display' => 'Phone 2',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'fax',
+ 'display' => 'Fax Number',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'member_contact_email',
+ 'display' => 'Email on Website',
+ 'opts' => array('class' => 'text')
+ );
+ /*
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'country',
+ 'display' => 'Country',
+ 'opts' => array(
+ '' => '-- Select Country --',
+ 'USA' => 'USA',
+ 'Canada' => 'Canada'
+ )
+ );
+ */
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'url',
+ 'display' => 'Website Address',
+ 'opts' => array('class' => 'text'),
+ 'noCharLimit' => true
+ );
+
+ // }}}
+ // {{{ Member Categories
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'memberCategoriesHdr',
+ 'display' => "$singularType Categories",
+ 'col1' => true
+ );
+ $e[] = array(
+ 'type' => 'select3',
+ 'req' => false,
+ 'name' => 'member_cats[]',
+ 'opts' => $this->categories,
+ 'att' => array('id' => 'categories')
+ );
+
+ // }}}
+ // {{{ Physical Address
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'physicalAddressHdr',
+ 'display' => 'Street Address',
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'street',
+ 'display' => 'Street Address',
+ 'opts' => array('class' => 'text')
+ );
+ if ($useCtrlCities) {
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => true,
+ 'name' => 'city_id',
+ 'display' => 'City',
+ 'opts' => array('' => '-- Select --') + $this->cities
+ );
+ } else {
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => true,
+ 'name' => 'city',
+ 'display' => 'City',
+ 'opts' => array('class' => 'text')
+ );
+ }
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => true,
+ 'name' => 'state_id',
+ 'display' => 'State / Province',
+ 'opts' => array('' => '-- Select --') + $this->states
+ );
+ if ($allowRegions) {
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'region',
+ 'display' => 'Region',
+ 'opts' => $this->getRegions()
+ );
+ }
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => true,
+ 'name' => 'zip',
+ 'display' => 'Zip / Postal Code',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'lat',
+ 'display' => 'Latitude',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'lon',
+ 'display' => 'Longitude',
+ 'opts' => array('class' => 'text')
+ );
+
+ // }}}
+ // {{{ Mailing Address
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'MailingAddressHdrRmv',
+ 'display' => 'Mailing Address (if different than physical address)',
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'mailing_address',
+ 'display' => 'Mailing Address',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'mailing_city',
+ 'display' => 'City',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'mailing_state_id',
+ 'display' => 'State / Province',
+ 'opts' => array('' => '-- Select --') + $this->states
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'mailing_zip',
+ 'display' => 'Zip / Postal Code',
+ 'opts' => array('class' => 'text')
+ );
+
+ // }}}
+ // {{{ Member Description
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'memberDescHdr',
+ 'display' => "$singularType Description",
+ 'col1' => true
+ );
+ $e[] = array(
+ 'type' => 'textarea',
+ 'req' => false,
+ 'name' => 'description',
+ 'display' => null,
+ 'opts' => array(
+ 'id' => 'description',
+ 'rows' => 8,
+ 'cols' => 43
+ ),
+ 'noCharLimit' => true
+ );
+
+ // }}}
+ // {{{ Account Info
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'accountInfoHdr',
+ 'display' => 'Account Info',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'member_login',
+ 'display' => 'Username',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'member_passwd',
+ 'display' => 'Password',
+ 'opts' => array('class' => 'text')
+ );
+
+ // }}}
+ // {{{ Main Image
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'logoHdr',
+ 'display' => 'Main Image',
+ 'col2' => true
+ );
+ if ($this->hasLogo()) {
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'remove_logo_rmv',
+ 'display' => 'Remove Image'
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'image_rmv',
+ 'display' => 'Current Image'
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'old_logo_rmv'
+ );
+ }
+
+ $e[] = array(
+ 'type' => 'file',
+ 'req' => false,
+ 'name' => 'new_logo_rmv',
+ 'display' => 'New Image',
+ 'opts' => array('class' => 'file')
+ );
+
+ // }}}
+ // {{{ Payment Type Accepted
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'CreditCardsHdr',
+ 'display' => 'Payment Type Accepted',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'creditCards[American Express]',
+ 'display' => 'American Express'
+ );
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'creditCards[Discover]',
+ 'display' => 'Discover'
+ );
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'creditCards[Master Card]',
+ 'display' => 'Master Card'
+ );
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'creditCards[Visa]',
+ 'display' => 'Visa'
+ );
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'creditCards[Diners]',
+ 'display' => 'Diners'
+ );
+
+ // }}}
+ // {{{ Accommodations Information
+
+ if ($this->accommodations) {
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'AccommodationsHdr',
+ 'display' => 'Accommodations Information',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'reservation_url',
+ 'display' => 'Reservation Url',
+ 'opts' => array('class' => 'text')
+ );
+ if ($usesGlmReservations) {
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'reservation_id',
+ 'display' => 'Reservation Id',
+ 'opts' => array('class' => 'text')
+ );
+ }
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'num_rooms',
+ 'display' => 'Number of Rooms',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'year_round',
+ 'display' => 'Open all Year',
+ 'val' => array(0, 1)
+ );
+ }
+
+ // }}}
+ // {{{ Restaurant Information
+
+ if ($this->restaurant) {
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'RestaurantHdr',
+ 'display' => 'Restaurant Information',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'breakfast',
+ 'display' => 'Breakfast',
+ 'att' => array('id' => 'breakfast'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'breakfast_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'breakfast_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'brunch',
+ 'display' => 'Brunch',
+ 'att' => array('id' => 'brunch'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'brunch_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'brunch_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'lunch',
+ 'display' => 'Lunch',
+ 'att' => array('id' => 'lunch'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'lunch_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'lunch_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'dinner',
+ 'display' => 'Dinner',
+ 'att' => array('id' => 'dinner'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'dinner_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'dinner_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'alcohol',
+ 'display' => 'Alcohol',
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'advcheckbox',
+// 'req' => false,
+// 'name' => 'non_smoking',
+// 'display' => 'Non-Smoking',
+// 'val' => array(0, 1)
+// );
+ }
+
+ // }}}
+ // {{{ Golf Information
+
+ if ($this->golf) {
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'GolfingHdr',
+ 'display' => 'Golf Course Information',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'res_url',
+ 'display' => 'TeeTime URL',
+ 'opts' => array('class' => 'text'),
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'par',
+ 'display' => 'Par',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'yardage',
+ 'display' => 'Yardage',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'course_rating',
+ 'display' => 'Course Rating',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'slope_rating',
+ 'display' => 'Slope Rating',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'walking_course',
+ 'display' => 'Walking Course',
+ 'val' => array(0, 1)
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'holes18',
+ 'display' => '18 Holes',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'holes9',
+ 'display' => '9 Holes',
+ 'opts' => array('class' => 'text')
+ );
+ }
+
+ // }}}
+ // {{{ Social Media Links
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'SocialMediaHdr',
+ 'display' => 'Social Media Links',
+ 'col2' => true,
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'facebook',
+ 'display' => 'Facebook',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'twitter',
+ 'display' => 'Twitter',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'pinterest',
+ 'display' => 'Pinterest',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'instagram',
+ 'display' => 'Instagram',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'google_plus',
+ 'display' => 'Google+',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'linkedin',
+ 'display' => 'LinkedIn',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'blog',
+ 'display' => 'Blog',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'youtube',
+ 'display' => 'YouTube',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'myspace',
+ 'display' => 'MySpace',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+
+ // }}}
+
+ $this->setupElements($e);
+ }
+
+ // }}}
+ // {{{ configureFilters()
+
+ /**
+ * Setup the filters to apply to the elements before we are
+ * handed the values submitted
+ *
+ * @return void
+ * @access public
+ */
+ public function configureFilters()
+ {
+ $f = array();
+ $f[] = array(
+ 'element' => '__ALL__',
+ 'filter' => 'trim'
+ );
+ $f[] = array(
+ 'element' => 'reservation_url',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'facebook',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'pinterest',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'twitter',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'instagram',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'google_plus',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'myspace',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'linkedin',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'blog',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'youtube',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+ $f[] = array(
+ 'element' => 'url',
+ 'filter' => array('Toolkit_Common', 'filterURI')
+ );
+// $f[] = array(
+// 'element' => 'phone',
+// 'filter' => array('Toolkit_Common', 'filterPhone')
+// );
+// $f[] = array(
+// 'element' => 'fax',
+// 'filter' => array('Toolkit_Common', 'filterPhone')
+// );
+// $f[] = array(
+// 'element' => 'toll_free',
+// 'filter' => array('Toolkit_Common', 'filterPhone')
+// );
+
+ $this->setupFilters($f);
+ }
+
+ // }}}
+ // {{{ configureForm()
+
+ /**
+ * Wrapper function to handle setting up the form
+ *
+ * @return void
+ * @access public
+ */
+ public function configureForm()
+ {
+ $this->configureElements();
+ $this->configureFilters();
+ $this->configureRules();
+ $this->configureDefaults();
+ $this->configureConstants();
+ }
+
+ // }}}
+ // {{{ configureModules()
+
+ /**
+ * Turns on a modules if the member has the appropriate category
+ *
+ * @return void
+ * @access protected
+ */
+ protected function configureModules()
+ {
+ if (is_array($this->memberCategories)) {
+ try {
+ $sql = "
+ SELECT *
+ FROM category
+ WHERE category_id = :cid";
+ $stmt = $this->dbh->prepare($sql);
+ foreach ($this->memberCategories as $cid => $v) {
+ $stmt->bindParam(':cid', $cid, PDO::PARAM_INT);
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ if ($row['accommodations'] == 't') {
+ $this->accommodations = true;
+ }
+ if ($row['restaurant'] == 't') {
+ $this->restaurant = true;
+ }
+ if ($row['golf'] == 't') {
+ $this->golf = true;
+ }
+ }
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+ }
+
+ // }}}
+ // {{{ configureRules()
+
+ /**
+ * Sets up all the rules to be used when the form is validated.
+ *
+ * @return void
+ * @access public
+ */
+ public function configureRules()
+ {
+ $mimeTypes = array(
+ 'image/jpe',
+ 'image/jpeg',
+ 'image/jpg',
+ 'image/jfif',
+ 'image/pjpeg',
+ 'image/pjp',
+ 'image/gif',
+ 'image/png',
+ );
+
+ $r = array();
+
+ $r[] = array(
+ 'element' => 'reservation_id',
+ 'message' => 'ERROR: Must be an integer!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'process_email',
+ 'message' => 'ERROR: Invalid email format!',
+ 'type' => 'checkEmail',
+ 'format' => array('use_rfc822' => true),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'member_contact_email',
+ 'message' => 'ERROR: Invalid email format!',
+ 'type' => 'checkEmail',
+ 'format' => array('use_rfc822' => true),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'join_date',
+ 'message' => 'ERROR: Invalid date!',
+ 'type' => 'callback',
+ 'format' => array(&$this, 'checkDate'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'url',
+ 'message' => 'ERROR: Invalid URL format',
+ 'type' => 'checkURI',
+ 'format' => array(
+ 'allowed_schemes' => array('http', 'https'),
+ 'strict' => false
+ ),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'reservation_url',
+ 'message' => 'ERROR: Invalid URL format',
+ 'type' => 'checkURI',
+ 'format' => array(
+ 'allowed_schemes' => array('http', 'https'),
+ 'strict' => false
+ ),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'num_rooms',
+ 'message' => 'ERROR: Must be an integer!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'lat',
+ 'message' => 'ERROR: Must be a numeric!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'lat',
+ 'message' => 'ERROR: Latitude out of range!',
+ 'type' => 'callback',
+ 'format' => array(&$this, 'checkLatitude'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'lon',
+ 'message' => 'ERROR: Must be a numeric!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'lon',
+ 'message' => 'ERROR: Longitude out of range!',
+ 'type' => 'callback',
+ 'format' => array(&$this, 'checkLongitude'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $allowDuplicateMemberNames
+ = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'duplicateMembers')
+ ->getContent();
+ if (!$allowDuplicateMemberNames) {
+ $r[] = array(
+ 'element' => 'member_name',
+ 'message' => 'ERROR: There is an existing account with this name!',
+ 'type' => 'callback',
+ 'format' => array($this, 'checkMemberName'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ }
+ $r[] = array(
+ 'element' => 'member_login',
+ 'message' => 'ERROR: Sorry, but this username has already been taken!',
+ 'type' => 'callback',
+ 'format' => array($this, 'checkUName'),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'state_id',
+ 'message' => 'ERROR: Invalid State!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'mailing_state_id',
+ 'message' => 'ERROR: Invalid State!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'region',
+ 'message' => 'ERROR: Invalid Region!',
+ 'type' => 'numeric',
+ 'format' => null,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'zip',
+ 'message' => 'ERROR: Invalid Zip Code!',
+ 'type' => 'zip',
+ 'format' => array('requireDBCheck' => false),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'mailing_zip',
+ 'message' => 'ERROR: Invalid Zip Code!',
+ 'type' => 'zip',
+ 'format' => array('requireDBCheck' => false),
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'new_logo_rmv',
+ 'message' => 'ERROR: Incorrect File Type (.gif, .png, .jpg) only!',
+ 'type' => 'mimetype',
+ 'format' => $mimeTypes,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'facebook',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'twitter',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'pinterest',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'instagram',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'google_plus',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'myspace',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'linkedin',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'blog',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'youtube',
+ 'message' => 'ERROR: 200 characters max!',
+ 'type' => 'maxlength',
+ 'format' => 200,
+ 'validatios' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+
+ $this->setupRules($r);
+ }
+
+ // }}}
+
+ // {{{ emailOwner()
+
+ /**
+ * Emails the owner and anyone else who wants to be advised of updates
+ *
+ * A false value in the primaryAdvisee will cause no email to be sent.
+ * all secondary advisees listed in the constructor are carbon copied
+ * in the email.
+ *
+ * Emails are sent out in both HTML and TXT forms.
+ *
+ * @return boolean result of email
+ * @access protected
+ */
+ protected function emailOwner()
+ {
+ if ($this->primaryAdvisee === false) {
+ return;
+ } else {
+ try {
+ $sql = "
+ SELECT member_name
+ FROM member
+ WHERE member_id = :member_id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $_GET['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ $memberName = $row['member_name'];
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ $template = new HTML_Template_Flexy($this->flexyOptions);
+ $page = new stdClass();
+ $page->member = $memberName;
+ $page->url = ($_SERVER['HTTPS'] == 'on') ? BASE_SECURE_URL : MEDIA_BASE_URL;
+ $page->email = DO_NOT_REPLY_EMAIL;
+ $page->siteName = SITENAME;
+ $page->link = 'link';
+
+ $template->compile($this->emailTemplate);
+ // Merge the compiled template with the $page object.
+ $htmlMsg = $template->bufferedOutputObject($page);
+
+ $msg = "
+
$memberName
+ ';
+
+ // If the old_logo_rmv key is set and not empty
+ // then we are replacing an existing logo and did not
+ // check the remove logo checkbox.
+ // remove this old logo just for good house keeping.
+ if (isset($values['old_logo_rmv']) && !empty($values['old_logo_rmv'])) {
+ $imgServer->imageDelete($values['old_logo_rmv']);
+ // update the elements on the form if we are replacing an existing logo.
+ if ($this->elementExists('old_logo_rmv')) {
+ $e =& $this->getElement('old_logo_rmv');
+ $e->setValue($imgName);
+ }
+ if ($this->elementExists('image_rmv')) {
+ $e =& $this->getElement('image_rmv');
+ $e->setValue($img);
+ }
+ } else {
+ $source =& $this->createElement(
+ 'checkbox',
+ 'remove_logo_rmv',
+ 'Remove Logo'
+ );
+ $this->insertElementBefore($source, 'new_logo_rmv');
+
+ $source =& $this->addElement('hidden', 'old_logo_rmv');
+ $source->setValue($imgName);
+
+ $source =& $this->createElement(
+ 'static',
+ 'image_rmv',
+ 'Current Image'
+ );
+ $source->setValue($img);
+ $element = $this->insertElementBefore($source, 'new_logo_rmv');
+
+ if (PEAR::isError($element)) {
+ die ('there was an error uploading your file!');
+ } else {
+ // I don't know why, but the insertElementBefore
+ // function was erasing the value we set earlier.
+ // so just reset it to make double sure its there.
+ $element->setValue($img);
+ }
+ }
+ }
+
+ // We clicked to remove the logo and did not upload a new one.
+ if ($values['remove_logo_rmv'] == 1 && $values['new_logo_rmv']['size'] == 0) {
+ if ($this->elementExists('remove_logo_rmv')) {
+ $this->removeElement('remove_logo_rmv', false);
+ }
+ if ($this->elementExists('image_rmv')) {
+ $this->removeElement('image_rmv', false);
+ }
+ if ($this->elementExists('old_logo_rmv')) {
+ $this->removeElement('old_logo_rmv', false);
+ }
+ }
+ }
+
+ // }}}
+
+ // {{{ removeCategories()
+
+ /**
+ * Remove categories from the values['member_cats'] array
+ *
+ * Any values in the removeCats array are removed from the
+ * values['member_cats'] array which is passed in by reference
+ * so we don't have to return any values.
+ *
+ * @param array $targets All the category id's we want to remove
+ * @param array &$values All the categories submitte.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function removeCategories($targets, &$values)
+ {
+ foreach ($targets as $cid) {
+ $key = array_search($cid, $values);
+ unset($values[$key]);
+ }
+ }
+
+ // }}}
+
+ // {{{ setConfig()
+
+ /**
+ * Sets the query to use to fetch the datagrid results
+ *
+ * @param Config_Container $c Configuration object
+ *
+ * @return void
+ * @access public
+ */
+ public function setConfig(Config_Container $c)
+ {
+ $this->config = $c;
+ }
+
+ // }}}
+ // {{{ setStates()
+
+ /**
+ * Set the states available for the form
+ *
+ * @param array $states Array of states available for the form
+ *
+ * @return void
+ * @access public
+ */
+ public function setStates(array $states)
+ {
+ $this->states = $states;
+ }
+
+ // }}}
+ // {{{ setCities()
+
+ /**
+ * Set the cities available for the form
+ *
+ * @param array $cities Array of cities available for the form
+ *
+ * @return void
+ * @access public
+ */
+ public function setCities(array $cities)
+ {
+ $this->cities = $cities;
+ }
+
+ // }}}
+ // {{{ setLatLngCoords()
+
+ /**
+ * Description for setLatLngCoords()
+ *
+ * @param array &$values Values array
+ *
+ * @return void|mixed Only on pdo error
+ * @access protected
+ */
+ protected function setLatLngCoords(&$values)
+ {
+ $geocoder = new GeocodeYahoo();
+
+ $sql = "
+ SELECT c.city_name, s.state_abb
+ FROM city c, state s
+ WHERE c.city_id = :cityId
+ AND s.state_id = :stateId";
+
+ try {
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':cityId', $values['city_id'], PDO::PARAM_INT);
+ $stmt->bindParam(':stateId', $values['state_id'], PDO::PARAM_INT);
+ $stmt->execute();
+ $stmt->bindColumn('city_name', $cityName);
+ $stmt->bindColumn('state_abb', $stateName);
+ $stmt->fetch(PDO::FETCH_ASSOC);
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+
+ $address = array(
+ 'city' => $cityName,
+ 'state' => $stateName,
+ 'zip' => $values['zip'],
+ );
+ if (!empty($values['street'])) {
+ $address['street'] = $values['street'];
+ }
+
+ if ( $this->elementExists('lat')
+ && $this->elementExists('lon')
+ ) {
+ try {
+ $response = $geocoder->geocodeAddress($address);
+ $responseArray = unserialize($response);
+ if ($responseArray['ResultSet']['Result'][0]['Latitude']) {
+ $values['lat'] = $responseArray['ResultSet']['Result'][0]['Latitude'];
+ $values['lon'] = $responseArray['ResultSet']['Result'][0]['Longitude'];
+ } else {
+ $values['lat'] = $responseArray['ResultSet']['Result']['Latitude'];
+ $values['lon'] = $responseArray['ResultSet']['Result']['Longitude'];
+ }
+
+ $lat =& $this->getElement('lat');
+ $lat->setValue($values['lat']);
+ $lng =& $this->getElement('lon');
+ $lng->setValue($values['lon']);
+ } catch (BadMethodCallException $e) {
+ Toolkit_Logger::logException('Invalid Arg', $e);
+ } catch (Exception $e) {
+ Toolkit_Logger::logException('Yahoo GeoCode', $e);
+ }
+ }
+ }
+
+ // }}}
+ // {{{ setupFormCategories()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupFormCategories()
+ {
+ try {
+ // Determine if this is a new member record or we're editing
+ // an existing member record.
+ $member_id = $_GET['id'];
+ // Get all the categories already associated w/ this member.
+ // This part is primarily for editing existing members.
+ // That way they categories initially show up.
+ // They are ordered by the mem_cat_id which should keep
+ // them in the same order as they were added.
+ $sql = "
+ SELECT *
+ FROM member_category
+ WHERE member_id = :id
+ ORDER BY member_category_id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $member_id, PDO::PARAM_INT);
+ $stmt->execute();
+
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $memCats[$row['category_id']] = true;
+ }
+
+ // If we submitted the form:
+ // 1. Get all the member_cat values on the form that were submitted.
+ // If we flip the key/value pairs when we add the submitted values
+ // we won't have to worry about checking for duplicate cats submitted.
+ // 2. If we clicked on a remove button determine the x/y coords
+ // (hint: the coords will be empty if we didn't click on one).
+ // if the coords are not empty, then remove the category we clicked
+ // on, it will be the removeCat form element.
+ if ($this->isSubmitted()) {
+ if (!is_array($memCats)) {
+ $memCats = array();
+ }
+ $submittedMemberCats = $this->getSubmitValue('member_cats');
+ if (is_array($submittedMemberCats) && !empty($submittedMemberCats)) {
+ $memCats += array_flip($this->getSubmitValue('member_cats'));
+ }
+ // Holds a possible array of category id's we want to remove.
+ $removeTargets = $this->getSubmitValue('removeCat');
+ // If the array is not empty, then scoot through it and remove
+ // any of the categories form the memCats array so they won't
+ // show up again.
+ if (!empty($removeTargets)) {
+ foreach ($removeTargets as $k => $v) {
+ unset($memCats[$v]);
+ }
+ }
+ }
+
+ // Unset the blank key so the sql query doesn't puke when trying to
+ // add it into the DB. The blank key will occur if no cat is selected.
+ // its the default option for the select list.
+ unset($memCats['']);
+ $this->memberCategories = $memCats;
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ setupRenderers()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ $renderer = new HTML_QuickForm_Renderer_Object(true);
+
+ $this->accept($renderer);
+
+ $this->template = new HTML_Template_Flexy($this->flexyOptions);
+
+ $m = new Toolkit_Members_RecordNavigation($this->config);
+ $m->setupAdminNavStructure();
+ // Make the view a copy of the $this object
+ // That way we have access to call functions in
+ // this class from within the template.
+ $this->view = $this;
+ $this->view->baseUrl = MEDIA_BASE_URL;
+ $this->view->form = $renderer->toObject();
+ $this->view->nav = $m->getPageNav();
+ $this->template->compile($this->formTemplate);
+ }
+
+ // }}}
+ // {{{ showCategories()
+
+ /**
+ * Creates the tags for the member categories
+ *
+ * @return string set of tags for categories assigned to a member
+ * @access public
+ */
+ public function showCategories()
+ {
+ if (!empty($this->memberCategories)) {
+ try {
+ $sql = "
+ SELECT *
+ FROM category
+ WHERE category_id = :cid";
+ $stmt = $this->dbh->prepare($sql);
+ $out = '';
+ foreach ($this->memberCategories as $cid => $v) {
+ $stmt->bindParam(':cid', $cid, PDO::PARAM_INT);
+ $stmt->execute();
+ $category = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ $out .= '';
+ $out .= '';
+ $out .= '';
+ $out .= $category['name'];
+ $out .= '';
+ }
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ return $out;
+ }
+
+ // }}}
+
+ // {{{ toHTML()
+
+ /**
+ * Renders the form
+ *
+ * sets the page the form should be redirected to instead of coming back
+ * around to itself.
+ *
+ * @return string The rendered form
+ * @access public
+ */
+ public function toHTML()
+ {
+ // We need to validate (and freeze if needed)
+ // before we render the form. That way the
+ // template knows about any errors on the form.
+ $this->validated = $this->validate();
+ if ($this->validated) {
+ $processed = $this->process(array(&$this, 'processData'), $this->mergeFiles);
+ }
+
+ // ProcessData handles settingup the lat/lon coordinates if they were not entered
+ // into the form. these values ar calculated and then inserted into the forms
+ // element values. So we need to process the data first and then render the form.
+ $this->setupRenderers();
+
+ return $this->template->bufferedOutputObject($this->view);
+ }
+
+ // }}}
+
+ // {{{ updateData()
+
+ /**
+ * Update the record data
+ *
+ * @param array $values scrubbed values submitted from the form
+ *
+ * @return object True on success
+ * @access public
+ */
+ public function updateData($values)
+ {
+ $addressUpdated = false;
+
+ $currentAddress = $this->getCurrentAddress();
+ // check current address with new one to see ifthere's a change
+ $newAddress = array(
+ 'street' => $values['street'],
+ 'city_id' => (int)$values['city_id'],
+ 'state_id' => (int)$values['state_id'],
+ 'zip' => $values['zip']
+ );
+ if ($newAddress != $currentAddress) {
+ $values['lat'] = '';
+ $values['lon'] = '';
+ }
+
+ $member_id = $_GET['id'];
+ // {{{ Golfing
+
+ // Remove Golf Fields for Special Insert.
+ $fields = array(
+ 'res_url',
+ 'par',
+ 'yardage',
+ 'course_rating',
+ 'slope_rating',
+ 'walking_course',
+ 'holes18',
+ 'holes9',
+ );
+
+ foreach ($fields as $v) {
+ $golfFields[$v] = $values[$v];
+ unset($values[$v]);
+ }
+
+ // }}}
+ // {{{ Accommodations
+
+ // Remove Accommodation Fields for Special Insert.
+ $fields = array(
+ 'reservation_url',
+ 'reservation_id',
+ 'num_rooms',
+ 'year_round',
+ );
+ foreach ($fields as $v) {
+ $accommodationFields[$v] = $values[$v];
+ unset($values[$v]);
+ }
+
+ // }}}
+ // {{{ Restaurant
+
+ // Remove Restaurant Fields for Special Insert.
+ $fields = array(
+ 'breakfast',
+ 'breakfast_from',
+ 'breakfast_to',
+ 'brunch',
+ 'brunch_from',
+ 'brunch_to',
+ 'lunch',
+ 'lunch_from',
+ 'lunch_to',
+ 'dinner',
+ 'dinner_from',
+ 'dinner_to',
+ 'alcohol',
+ 'non_smoking',
+ );
+ foreach ($fields as $v) {
+ $restaurantFields[$v] = $values[$v];
+ unset($values[$v]);
+ }
+
+ // }}}
+
+ if (empty($values['lat']) || empty($values['lon'])) {
+ try {
+ $this->setLatLngCoords($values);
+ } catch (Exception $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // Remove values not wanted before we get all the member categories.
+ if (isset($values['removeCat'])) {
+ // So remove them before we get the categories to insert for the member.
+ $this->removeCategories($values['removeCat'], $values['member_cats']);
+ }
+ // Now get the cats so we can insert them into a seperate table later.
+ $categories = $values['member_cats'];
+
+ $ccards = $values['creditCards'];
+ unset($values['member_cats'],
+ $values['removeCat'],
+ $values['creditCards']
+ );
+
+ try {
+ $params = array_keys($values);
+ $length = count($params);
+ for ($i = 0; $i < $length; ++$i) {
+ $bindParams .= "{$params[$i]} = :{$params[$i]}";
+ if ($i < ($length - 1)) {
+ $bindParams .= ', ';
+ }
+ }
+ $this->dbh->beginTransaction();
+ $sql = "
+ UPDATE {$this->tableName}
+ SET $bindParams
+ WHERE member_id = :member_id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $member_id, PDO::PARAM_INT);
+ foreach ($values as $k => &$v) {
+ $metaData = $this->tableMetaData[$k];
+ if ($metaData == 'integer') {
+ $dataType = PDO::PARAM_INT;
+ } else if ($metaData == 'boolean') {
+ $dataType = PDO::PARAM_BOOL;
+ } else {
+ $dataType = PDO::PARAM_STR;
+ }
+ // for empty values that are not actually a zero (0), we
+ // want to insert null's.
+ // This will help hold the unique values for member_logins,
+ // as empty values '', are not considered unique
+ if (empty($v) && $v !== 0) {
+ $v = null;
+ $dataType = PDO::PARAM_NULL;
+ }
+ $stmt->bindParam(":$k", $v, $dataType);
+ }
+ $stmt->execute();
+
+ // Handle updating the credit cards
+ $sql = "
+ DELETE FROM member_ccard_type
+ WHERE member_id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $member_id, PDO::PARAM_INT);
+ $stmt->execute();
+
+ if (is_array($ccards)) {
+ $sql = "
+ INSERT INTO member_ccard_type (member_id, ccard_type_id)
+ SELECT :id, ccard_type_id
+ FROM ccard_type
+ WHERE ccard_type_name = :cctn";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $member_id, PDO::PARAM_INT);
+ foreach ($ccards as $k => &$v) {
+ if ($v) {
+ $stmt->bindParam(':cctn', $k, PDO::PARAM_STR);
+ $stmt->execute();
+ }
+ }
+ }
+
+ // Handle updating the categories
+ $sql = "
+ DELETE FROM member_category
+ WHERE member_id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $member_id, PDO::PARAM_INT);
+ $stmt->execute();
+
+ if (is_array($categories)) {
+ $sql = "
+ INSERT INTO member_category (member_id, category_id)
+ VALUES (:member_id, :cid)";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $member_id, PDO::PARAM_INT);
+ foreach ($categories as &$cid) {
+ if (!empty($cid)) {
+ $stmt->bindParam(':cid', $cid, PDO::PARAM_INT);
+ $stmt->execute();
+ }
+ }
+ }
+
+ $golf = $restaurant = $accommodations = false;
+ if (!empty($categories)) {
+ $sql = "
+ SELECT *
+ FROM category
+ WHERE category_id = :cid";
+ $stmt = $this->dbh->prepare($sql);
+ foreach ($categories as &$cid) {
+ if (!empty($cid)) {
+ $stmt->bindParam(':cid', $cid, PDO::PARAM_INT);
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ // If any of the module statuses are true, set them.
+ // otherwise leave them as they were, (we don't want
+ // to set a true back to a false).
+ $golf = ($row['golf'] == 't') ? true : $golf;
+ $accommodations = ($row['accommodations'] == 't') ?
+ true : $accommodations;
+ $restaurant = ($row['restaurant'] == 't') ?
+ true : $restaurant;
+ }
+ }
+ }
+ $this->clearModule('member_golf');
+ if ($golf) {
+ $this->updateModuleFields($golfFields, 'member_golf');
+ }
+ $this->clearModule('member_accommodations');
+ if ($accommodations) {
+ $this->updateModuleFields($accommodationFields, 'member_accommodations');
+ }
+ $this->clearModule('member_restaurants');
+ if ($restaurant) {
+ $this->updateModuleFields($restaurantFields, 'member_restaurants');
+ }
+
+ $cache = new Cache_Lite(Toolkit_Members::getCacheOptions());
+ $cache->remove("Member-{$_GET['id']}", 'Profile');
+
+ $ret = $this->dbh->commit();
+
+ $this->addMemberToStreamSend($_GET['id']);
+
+ return $ret;
+ } catch (PDOException $e) {
+ $this->dbh->rollBack();
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ updateModuleFields()
+
+ // member_id in the params is for inserting the data if the form fails validation
+ // first and comes back around and module categories will be included on the form
+ // and you need to be able to insert the data and associate to the member.
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ * @param unknown $tableName Parameter description (if any) ...
+ * @param unknown $member_id Parameter description (if any) ...
+ *
+ * @return object Return description (if any) ...
+ * @access protected
+ */
+ protected function updateModuleFields(
+ $values,
+ $tableName,
+ $member_id = null
+ ) {
+ $this->tableMetaData = Toolkit_Common::getTableMetaData(
+ $this->dbh,
+ $tableName
+ );
+ $values['member_id'] = !is_null($member_id)
+ ? $member_id
+ : $_GET['id'];
+ try {
+ $params = implode(', ', array_keys($values));
+ $bindParams = ':' . implode(', :', array_keys($values));
+ $sql = "
+ INSERT INTO $tableName ($params)
+ VALUES ($bindParams)";
+ $stmt = $this->dbh->prepare($sql);
+ foreach ($values as $k => &$v) {
+ $metaData = $this->tableMetaData[$k];
+ if ($metaData == 'integer') {
+ $dataType = PDO::PARAM_INT;
+ } else if ($metaData == 'boolean') {
+ $dataType = PDO::PARAM_BOOL;
+ } else {
+ $dataType = PDO::PARAM_STR;
+ }
+ // for empty values that are not actually a zero (0), we
+ // want to insert null's.
+ // This will help hold the unique values for member_logins,
+ // as empty values '', are not considered unique
+ if (empty($v) && $v !== 0) {
+ $v = null;
+ $dataType = PDO::PARAM_NULL;
+ }
+ $stmt->bindParam(":$k", $v, $dataType);
+ }
+ return $stmt->execute();
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ validated()
+
+ /**
+ * Checks if the form is validated
+ *
+ * If the form is validated display the success msg.
+ * If the form is submitted but not validated, display
+ * the error msg. Other wise display nothing.
+ *
+ * This function is called from within the template.
+ *
+ * @return string The success or error msg for the user.
+ * @access protected
+ */
+ public function validated()
+ {
+ if ($this->validated) {
+ return $this->successMsg;
+ } elseif ($this->isSubmitted()) {
+ return $this->errorMsg;
+ }
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/EditMemberOnlyAmenities.php b/Toolkit/Members/EditMemberOnlyAmenities.php
new file mode 100644
index 0000000..1ced800
--- /dev/null
+++ b/Toolkit/Members/EditMemberOnlyAmenities.php
@@ -0,0 +1,454 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: EditMemberOnlyAmenities.php,v 1.14 2010/07/18 16:44:51 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ */
+
+/**
+ * Short description for class
+ *
+ * Long description (if any) ...
+ *
+ * @category MembersDB
+ * @package Toolkit_Members
+ * @author Jamie Kahgee
';
+ }
+
+ // }}}
+ // {{{ getMemberContacts()
+
+ /**
+ * Get all the contacts data uploaded to a member into an array
+ *
+ * @return array member contacts
+ * @access protected
+ */
+ protected function getMemberContacts()
+ {
+ try {
+ $sql = "
+ SELECT *
+ FROM {$this->tableName}
+ WHERE member_id = :id
+ ORDER BY id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $_GET['id'], PDO::PARAM_INT);
+ $stmt->execute();
+
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $contacts[] = $row;
+ }
+ return $contacts;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ insertData()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ *
+ * @return object Return description (if any) ...
+ * @access public
+ */
+ public function insertData($values)
+ {
+ unset(
+ $values['id'],
+ $values['target'],
+ $values['submit']
+ );
+ $values['member_id'] = $_GET['id'];
+ try {
+ $params = implode(', ', array_keys($values));
+ $bindParams = ':' . implode(', :', array_keys($values));
+ $sql = "
+ INSERT INTO {$this->tableName} ($params)
+ VALUES ($bindParams)";
+ $stmt = $this->dbh->prepare($sql);
+ foreach ($values as $k => $v) {
+ $metaData = $this->tableMetaData[$k];
+ if ($metaData == 'integer') {
+ $dataType = PDO::PARAM_INT;
+ } else if ($metaData == 'boolean') {
+ $dataType = PDO::PARAM_BOOL;
+ } elseif ($metaData == 'double precision') {
+ $dataType = null;
+ } else {
+ $dataType = PDO::PARAM_STR;
+ }
+ $stmt->bindParam(":$k", $values[$k], $dataType);
+ }
+ return $stmt->execute();
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ isEmail()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isEmail($name)
+ {
+ return (substr($name, 0, 5) == 'email');
+ }
+
+ // }}}
+ // {{{ isForm()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $sec Parameter description (if any) ...
+ *
+ * @return unknown Return description (if any) ...
+ * @access public
+ */
+ public function isForm($sec)
+ {
+ return !$sec;
+ }
+
+ // }}}
+ // {{{ isName()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isName($name)
+ {
+ return (substr($name, 0, 4) == 'name');
+ }
+
+ // }}}
+ // {{{ isPhone()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isPhone($name)
+ {
+ return (substr($name, 0, 5) == 'phone');
+ }
+
+ // }}}
+ // {{{ isTitle()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $name Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function isTitle($name)
+ {
+ return (substr($name, 0, 5) == 'title');
+ }
+
+ // }}}
+
+ // {{{ processData()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ *
+ * @return void
+ * @access public
+ */
+ public function processData($values)
+ {
+ $this->tableMetaData = Toolkit_Common::getTableMetaData(
+ $this->dbh,
+ $this->tableName
+ );
+ if (empty($values['id'])) {
+ $this->insertData($values);
+ } else {
+ $this->updateData($values);
+ }
+ $listPage = MEDIA_BASE_URL .
+ "members-only-area/?rt=EditProfile&tab=contacts";
+ header("Location: $listPage");
+ }
+
+ // }}}
+
+ // {{{ removeContact()
+
+ /**
+ * Remove a contact from a member record
+ *
+ * @param integer $cid contact id
+ * @param integer $mid member id
+ *
+ * @return void
+ * @access public
+ */
+ public function removeContact($cid, $mid)
+ {
+ try {
+ $sql = "
+ DELETE FROM {$this->tableName}
+ WHERE id = :cid
+ AND member_id = :mid";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':cid', $cid, PDO::PARAM_INT);
+ $stmt->bindParam(':mid', $mid, PDO::PARAM_INT);
+ $stmt->execute();
+ $target = MEDIA_BASE_URL .
+ "members-only-area/?rt=EditProfile&tab=contacts";
+ header("Location: $target");
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ setupRenderers()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ $renderer = new HTML_QuickForm_Renderer_Object(true);
+
+ $this->accept($renderer);
+
+ $this->template = new HTML_Template_Flexy($this->flexyOptions);
+
+ $m = new Toolkit_Members_RecordNavigation($this->config);
+ $m->setupUserNavStructure();
+ // Make the view a copy of the $this object
+ // That way we have access to call functions in
+ // this class from within the template.
+ $this->view = $this;
+ $this->view->form = $renderer->toObject();
+ $this->view->nav = $m->getPageNav();
+ $this->template->compile($this->formTemplate);
+ }
+
+ // }}}
+ // {{{ show()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access public
+ */
+ public function show()
+ {
+ if (isset($_GET['d'])) {
+ $this->removeContact($_GET['cid']);
+ $target = MEDIA_BASE_URL .
+ "members-only-area/?rt=EditProfile&tab=contacts";
+ header("Location: $target");
+ }
+ Toolkit_Common::show();
+ }
+
+ // }}}
+
+ // {{{ updateData()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ *
+ * @return object Return description (if any) ...
+ * @access public
+ */
+ public function updateData($values)
+ {
+ if (array_key_exists('delete', $values)) {
+ $this->deleteFile($values);
+ }
+
+ unset(
+ $values['target'],
+ $values['submit']
+ );
+
+ try {
+ $params = array_keys($values);
+ $length = count($params);
+ for ($i = 0; $i < $length; ++$i) {
+ $bindParams .= "{$params[$i]} = :{$params[$i]}";
+ if ($i < ($length - 1)) {
+ $bindParams .= ', ';
+ }
+ }
+ $sql = "
+ UPDATE {$this->tableName}
+ SET $bindParams
+ WHERE id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $pid, PDO::PARAM_INT);
+ foreach ($values as $k => $v) {
+ $metaData = $this->tableMetaData[$k];
+ if ($metaData == 'integer') {
+ $dataType = PDO::PARAM_INT;
+ } else if ($metaData == 'boolean') {
+ $dataType = PDO::PARAM_BOOL;
+ } else {
+ $dataType = PDO::PARAM_STR;
+ }
+ $stmt->bindParam(":$k", $values[$k], $dataType);
+ }
+ return $stmt->execute();
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/EditMemberOnlyFile.php b/Toolkit/Members/EditMemberOnlyFile.php
new file mode 100644
index 0000000..67628a4
--- /dev/null
+++ b/Toolkit/Members/EditMemberOnlyFile.php
@@ -0,0 +1,428 @@
+
+ * @author Jamie Kahgee
';
+ $label = '';
+ $update = false;
+ $dataType = 'boolean';
+ $field = 'pending';
+ $sql = "
+ INSERT INTO {$this->pendingTable}
+ (member_id, field, update, db_table, data_type, label, foreign_key)
+ VALUES
+ (:member_id, :field, :update, :db_table, :data_type, :label, :foreign_key)";
+
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $_GET['id'], PDO::PARAM_INT);
+ $stmt->bindParam(':field', $field, PDO::PARAM_STR);
+ $stmt->bindParam(':update', $update, PDO::PARAM_BOOL);
+ $stmt->bindParam(':db_table', $this->tableName, PDO::PARAM_STR);
+ $stmt->bindParam(':data_type', $dataType, PDO::PARAM_STR);
+ $stmt->bindParam(':label', $label, PDO::PARAM_STR);
+ $stmt->bindParam(':foreign_key', $file['id'], PDO::PARAM_STR);
+ $stmt->execute();
+ $this->emailOwner();
+ return $this->dbh->commit();
+ } catch (PDOException $e) {
+ $this->dbh->rollBack();
+ return Toolkit_Common::handleError($e);
+ }
+ } else {
+ return parent::insertData($values);
+ }
+ }
+
+ // }}}
+
+ // {{{ pendingClass()
+
+ /**
+ * Returns a pending class for the file if it is in a pending state
+ *
+ * The offset passed in is controlled from the loop in the template
+ * that creates each file form.
+ *
+ * @param integer $offset which file we're dealing with
+ *
+ * @return mixed
+ * @access Protected
+ * @see Toolkit_Members_EditMemberFile::getMemberFiles()
+ */
+ public function pendingClass($offset)
+ {
+ $files = $this->getMemberFiles();
+ // If the offset is empty (0) then we know we're dealing
+ // with the upload box.
+ if (empty($offset)) {
+ return;
+ } else {
+ // Otherwise we need to see if this file is pending or not.
+ try {
+ // Get all the files that are pending in the updates table.
+ $sql = "
+ SELECT DISTINCT foreign_key AS fid
+ FROM {$this->pendingTable}
+ WHERE db_table = '{$this->tableName}'
+ AND member_id = :member_id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $_GET['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $pendingFiles[] = $row['fid'];
+ }
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+
+ --$offset;
+
+ // If our current file is in the pending table
+ // return the pending class.
+ if ( is_array($files)
+ && is_array($pendingFiles)
+ && in_array($files[$offset]['id'], $pendingFiles)
+ ) {
+ return 'pending';
+ } else {
+ return;
+ }
+ }
+ }
+
+ // }}}
+ // {{{ processData()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $values Parameter description (if any) ...
+ *
+ * @return void
+ * @access public
+ */
+ public function processData($values)
+ {
+ $id = $GLOBALS['memberAuth']->getAuthData('member_id');
+ $cache = new Cache_Lite(Toolkit_Members::getCacheOptions());
+ $cache->remove("Member-$id", 'Profile');
+
+ parent::processData($values);
+ $listPage = MEDIA_BASE_URL .
+ "members-only-area/?rt=EditProfile&tab=files";
+ header("Location: $listPage");
+ }
+
+ // }}}
+
+ // {{{ setPending()
+
+ /**
+ * Determines if the member has made any update requests
+ *
+ * Any update requests that are in the member_updates table
+ * will let us know if this member is pending or not.
+ *
+ * @return boolean
+ * @access protected
+ */
+ public function setPending()
+ {
+ unset ($this->pendingFields);
+ try {
+ $sql = "
+ SELECT DISTINCT foreign_key AS fid
+ FROM {$this->pendingTable}
+ WHERE member_id = :member_id
+ AND db_table = '{$this->tableName}'";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $_GET['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $this->pendingFields[] = $row['fid'];
+ }
+ $this->pending = (count($this->pendingFields)) ? true : false;
+ return true;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ setupRenderers()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ $renderer = new HTML_QuickForm_Renderer_Object(true);
+
+ $this->accept($renderer);
+
+ $this->template = new HTML_Template_Flexy($this->flexyOptions);
+
+ $m = new Toolkit_Members_RecordNavigation($this->config);
+ $m->setupUserNavStructure();
+ // Make the view a copy of the $this object
+ // That way we have access to call functions in
+ // this class from within the template.
+ $this->view = $this;
+ $this->view->form = $renderer->toObject();
+ $this->view->nav = $m->getPageNav();
+ $this->template->compile($this->formTemplate);
+ }
+
+ // }}}
+
+ // {{{ updateData()
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param array $values Parameter description (if any) ...
+ *
+ * @return mixed Return description (if any) ...
+ * @access public
+ */
+ public function updateData($values)
+ {
+ if ($this->strictPending) {
+ if (array_key_exists('delete', $values)) {
+ return $this->deleteFile($values);
+ }
+ try {
+ $fid = $values["file{$values['target']}"];
+ $sql = "
+ SELECT *
+ FROM {$this->tableName}
+ WHERE id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $fid, PDO::PARAM_INT);
+ $stmt->execute();
+ $file = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ $fname = empty($file['file_name']) ?
+ $file['original_name'] :
+ $file['file_name'];
+ $imgTag = '
';
+ $label = '' .
+ $imgTag . $fname . '';
+
+ $dataType = 'text';
+ $label = '
';
+ $row['field'] = 'image_rmv';
+ }
+ $this->oldData[$row['field']] = $row['update'];
+ }
+ return $this->setupDefaults($this->oldData);
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ configureElements()
+
+ /**
+ * Setup the elements to use on the form.
+ *
+ * Categories are populated into the protected class property $categories.
+ * These categories are used to populate the select list of categories.
+ * Modules are configured before any elements are setup, that way we will
+ * know if we need to include them in the rendering of the form.
+ *
+ * @return void
+ * @access public
+ */
+ public function configureElements()
+ {
+ $e = array();
+
+ $singularType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'singular')
+ ->getContent();
+ $pluralType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'plural')
+ ->getContent();
+ $useCtrlCities = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'controlledCities')
+ ->getContent();
+ $allowRegions = $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'regions')
+ ->getContent();
+ $usesGlmReservations= $this->config
+ ->getItem('section', 'conf')
+ ->getItem('directive', 'glmReservations')
+ ->getContent();
+
+ $this->setupFormCategories();
+ $this->configureModules();
+
+ $this->getCategories();
+
+ // All Grouped Elements are created here.
+ // All Elements are created here. This includes group element definitions.
+
+ // {{{ Member Information
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'memberInfoHdr',
+ 'display' => "$singularType Information",
+ 'col1' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'primary_contact_fname',
+ 'display' => 'Primary Contact First Name',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'primary_contact_lname',
+ 'display' => 'Primary Contact Last Name',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'process_email',
+ 'display' => 'Primary Contact Email',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'phone',
+ 'display' => 'Primary Phone',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'toll_free',
+ 'display' => 'Phone 2',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'fax',
+ 'display' => 'Fax Number',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'member_contact_email',
+ 'display' => 'Email on Website',
+ 'opts' => array('class' => 'text')
+ );
+ /*
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'country',
+ 'display' => 'Country',
+ 'opts' => array(
+ '' => '-- Select Country --',
+ 'USA' => 'USA',
+ 'Canada' => 'Canada'
+ )
+ );
+ */
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'url',
+ 'display' => 'Website Address',
+ 'opts' => array('class' => 'text'),
+ 'noCharLimit' => true
+ );
+
+ // }}}
+ // {{{ Member Categories
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'memberCategoryHdr',
+ 'display' => "$singularType Categories",
+ 'col1' => true
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'member_cats[]',
+ 'opts' => $this->categories,
+ 'att' => array('id' => 'categories')
+ );
+
+ // }}}
+ // {{{ Physical Address
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'physicalAddressHdr',
+ 'display' => 'Street Address',
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'street',
+ 'display' => 'Street Address',
+ 'opts' => array('class' => 'text')
+ );
+ if ($useCtrlCities) {
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => true,
+ 'name' => 'city_id',
+ 'display' => 'City',
+ 'opts' => array('' => '-- Select --') + $this->cities
+ );
+ } else {
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => true,
+ 'name' => 'city',
+ 'display' => 'City',
+ 'opts' => array('class' => 'text')
+ );
+ }
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => true,
+ 'name' => 'state_id',
+ 'display' => 'State / Province',
+ 'opts' => array('' => '-- Select --') + $this->states
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => true,
+ 'name' => 'zip',
+ 'display' => 'Zip / Postal Code',
+ 'opts' => array('class' => 'text')
+ );
+
+ // }}}
+ // {{{ Mailing Address
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'MailingAddressHdrRmv',
+ 'display' => 'Mailing Address (if different than physical address)',
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'mailing_address',
+ 'display' => 'Mailing Address',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'mailing_city',
+ 'display' => 'City',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => false,
+ 'name' => 'mailing_state_id',
+ 'display' => 'State / Province',
+ 'opts' => array('' => '-- Select --') + $this->states
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'mailing_zip',
+ 'display' => 'Zip / Postal Code',
+ 'opts' => array('class' => 'text')
+ );
+
+ // }}}
+ // {{{ Member Description
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'memberDescHdr',
+ 'display' => "$singularType Description",
+ 'col1' => true
+ );
+ $e[] = array(
+ 'type' => 'textarea',
+ 'req' => false,
+ 'name' => 'description',
+ 'display' => 'Description',
+ 'opts' => array(
+ 'id' => 'description',
+ 'rows' => 8,
+ 'cols' => 43
+ ),
+ 'noCharLimit' => true
+ );
+
+ // }}}
+ // {{{ Account Info
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'accountInfoHdr',
+ 'display' => 'Account Info',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'member_login',
+ 'display' => 'Username',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'member_passwd',
+ 'display' => 'Password',
+ 'opts' => array('class' => 'text')
+ );
+
+ // }}}
+ // {{{ Main Image
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'logoHdr',
+ 'display' => 'Main Image',
+ 'col2' => true
+ );
+ if ($this->hasLogo()) {
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'remove_logo_rmv',
+ 'display' => 'Remove Image'
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'image_rmv',
+ 'display' => 'Current Image'
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'old_logo_rmv'
+ );
+ }
+
+ $e[] = array(
+ 'type' => 'file',
+ 'req' => false,
+ 'name' => 'new_logo_rmv',
+ 'display' => 'New Image',
+ 'opts' => array('class' => 'file')
+ );
+
+ // }}}
+ // {{{ Payment Type Accepted
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'CreditCardsHdr',
+ 'display' => 'Payment Type Accepted',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'creditCards[American Express]',
+ 'display' => 'American Express',
+ 'val' => array(0, 1)
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'creditCards[Discover]',
+ 'display' => 'Discover',
+ 'val' => array(0, 1)
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'creditCards[Master Card]',
+ 'display' => 'Master Card',
+ 'val' => array(0, 1)
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'creditCards[Visa]',
+ 'display' => 'Visa',
+ 'val' => array(0, 1)
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'creditCards[Diners]',
+ 'display' => 'Diners'
+ );
+
+ // }}}
+ // {{{ Accommodations Information
+
+ if ($this->accommodations) {
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'AccommodationsHdr',
+ 'display' => 'Accommodations Information',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'reservation_url',
+ 'display' => 'Reservation Url',
+ 'opts' => array('class' => 'text')
+ );
+ if ($usesGlmReservations) {
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'reservation_id',
+ 'display' => 'Reservation Id',
+ 'opts' => array('class' => 'text')
+ );
+ }
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'num_rooms',
+ 'display' => 'Number of Rooms',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'year_round',
+ 'display' => 'Open all Year',
+ 'val' => array(0, 1)
+ );
+ }
+
+ // }}}
+ // {{{ Restaurant Information
+
+ if ($this->restaurant) {
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'RestaurantHdr',
+ 'display' => 'Restaurant Information',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'breakfast',
+ 'display' => 'Breakfast',
+ 'att' => array('id' => 'breakfast'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'breakfast_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'breakfast_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'brunch',
+ 'display' => 'Brunch',
+ 'att' => array('id' => 'brunch'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'brunch_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'brunch_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'lunch',
+ 'display' => 'Lunch',
+ 'att' => array('id' => 'lunch'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'lunch_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'lunch_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'dinner',
+ 'display' => 'Dinner',
+ 'att' => array('id' => 'dinner'),
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'dinner_from',
+// 'display' => 'From',
+// 'opts' => array('class' => 'priceFrom')
+// );
+// $e[] = array(
+// 'type' => 'text',
+// 'req' => false,
+// 'name' => 'dinner_to',
+// 'display' => 'To',
+// 'opts' => array('class' => 'priceTo')
+// );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'alcohol',
+ 'display' => 'Alcohol',
+ 'val' => array(0, 1)
+ );
+// $e[] = array(
+// 'type' => 'advcheckbox',
+// 'req' => false,
+// 'name' => 'non_smoking',
+// 'display' => 'Non-Smoking',
+// 'val' => array(0, 1)
+// );
+ }
+
+ // }}}
+ // {{{ Golf Information
+
+ if ($this->golf) {
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'GolfingHdr',
+ 'display' => 'Golf Course Information',
+ 'col2' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'res_url',
+ 'display' => 'TeeTime URL',
+ 'opts' => array('class' => 'text'),
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'par',
+ 'display' => 'Par',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'yardage',
+ 'display' => 'Yardage',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'course_rating',
+ 'display' => 'Course Rating',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'slope_rating',
+ 'display' => 'Slope Rating',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'advcheckbox',
+ 'req' => false,
+ 'name' => 'walking_course',
+ 'display' => 'Walking Course',
+ 'val' => array(0, 1)
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'holes18',
+ 'display' => '18 Holes',
+ 'opts' => array('class' => 'text')
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'holes9',
+ 'display' => '9 Holes',
+ 'opts' => array('class' => 'text')
+ );
+ }
+
+ // }}}
+ // {{{ Social Media Links
+
+ $e[] = array(
+ 'type' => 'header',
+ 'req' => false,
+ 'name' => 'SocialMediaHdr',
+ 'display' => 'Social Media Links',
+ 'col2' => true,
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'facebook',
+ 'display' => 'Facebook',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'twitter',
+ 'display' => 'Twitter',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'pinterest',
+ 'display' => 'Pinterest',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'instagram',
+ 'display' => 'Instagram',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'google_plus',
+ 'display' => 'Google+',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'linkedin',
+ 'display' => 'LinkedIn',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'blog',
+ 'display' => 'Blog',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'youtube',
+ 'display' => 'YouTube',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'myspace',
+ 'display' => 'MySpace',
+ 'col2' => true,
+ 'noCharLimit' => true
+ );
+
+ // }}}
+
+ $this->setupElements($e);
+ }
+
+ // }}}
+
+ // {{{ processData()
+
+ /**
+ * Handles processing the submitted forms data
+ *
+ * See parent function for better description.
+ *
+ * @param array $values The array of all submitted form values.
+ *
+ * @return boolean Whether the insert/update succeeded.
+ * @access public
+ * @see Toolkit_Members_EditMemberInfo::processData()
+ */
+ public function processData($values)
+ {
+ $id = $GLOBALS['memberAuth']->getAuthData('member_id');
+ $cache = new Cache_Lite(Toolkit_Members::getCacheOptions());
+ $cache->remove("Member-$id", 'Profile');
+
+ $return = parent::processData($values);
+ $this->setPending();
+ return $return;
+ }
+
+ // }}}
+
+ // {{{ setPending()
+
+ /**
+ * Determines if the member has made any update requests
+ *
+ * Any update requests that are in the member_updates table
+ * will let us know if this member is pending or not.
+ *
+ * @return void
+ * @access public
+ */
+ public function setPending()
+ {
+ unset ($this->pendingFields);
+ try {
+ $sql = "
+ SELECT DISTINCT
+ CASE field
+ WHEN 'lat' THEN 'latitude'
+ WHEN 'lon' THEN 'longitude'
+ WHEN 'logo' THEN 'image_rmv'
+ ELSE field
+ END AS field
+ FROM {$this->pendingTable}
+ WHERE member_id = :member_id
+ AND (db_table = '{$this->tableName}'
+ OR db_table = 'member_ccard_type'
+ OR db_table = 'member_restaurants'
+ OR db_table = 'member_accommodations'
+ OR db_table = 'member_golf')";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $_GET['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ $this->pendingFields[] = $row['field'];
+ }
+ $this->pending = (count($this->pendingFields));
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ setupRenderers()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ $renderer = new HTML_QuickForm_Renderer_Object(true);
+
+ $this->accept($renderer);
+
+ $this->template = new HTML_Template_Flexy($this->flexyOptions);
+
+ $m = new Toolkit_Members_RecordNavigation($this->config);
+ $m->setupUserNavStructure();
+ // Make the view a copy of the $this object
+ // That way we have access to call functions in
+ // this class from within the template.
+ $this->view = $this;
+ $this->view->form = $renderer->toObject();
+ $this->view->nav = $m->getPageNav();
+ $this->template->compile($this->formTemplate);
+ }
+
+ // }}}
+ // {{{ showCategories()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return string Return description (if any) ...
+ * @access public
+ */
+ public function showCategories()
+ {
+ if (!empty($this->memberCategories)) {
+ try {
+ $sql = "
+ SELECT *
+ FROM category
+ WHERE category_id = :cid";
+ $stmt = $this->dbh->prepare($sql);
+ foreach ($this->memberCategories as $cid => $v) {
+ $stmt->bindParam(':cid', $cid, PDO::PARAM_INT);
+ $stmt->execute();
+ $category = $stmt->fetch(PDO::FETCH_ASSOC);
+
+ $out .= '
+
+ ';
+ if ( defined('MEMBERS_ONLY_AREA_ON')
+ && MEMBERS_ONLY_AREA_ON == true
+ ) {
+ // do nothing
+ } else {
+ $out .= '
+ ';
+ }
+ $out .= "{$category['name']}";
+ }
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ return $out;
+ }
+
+ // }}}
+
+ // {{{ updateData()
+
+ /**
+ * Insert the values that were updated from the member only form
+ *
+ * 1. Get all the field types in the DB for the module tables
+ * 2. Check the module fields against the old Data (the original values
+ * we obtained when we got the defaults for the form). If the
+ * value is not the same, then add the value to the column field of
+ * the table in the moduleUpdates array.
+ * 3. Get the updates for the member record.
+ * 4. Insert all the updates into the member_updates table.
+ *
+ * @param array $values submitted form values
+ *
+ * @return mixed
+ * @access public
+ */
+ public function updateData($values)
+ {
+ if ($this->strictPending) {
+ foreach ($this->moduleTables as $tname => &$arr) {
+ $this->tableMetaData = Toolkit_Common::getTableMetaData(
+ $this->dbh,
+ $tname
+ );
+ if (is_array($this->tableMetaData)) {
+ foreach ($this->tableMetaData as $k => $v) {
+ switch ($k) {
+ case 'id' :
+ case 'member_id' :
+ break;
+
+ default :
+ $arr[$k]['data_type'] = $v;
+ $arr[$k]['value'] = $values[$k];
+ unset($values[$k]);
+ break;
+ }
+ }
+ }
+ }
+ // Check for updates in the module tables.
+ foreach ($this->moduleTables as $tname => &$arr) {
+ foreach ($arr as $k => $v) {
+ if (array_key_exists($k, $this->oldData)) {
+ if ($v['data_type'] != 'boolean') {
+ if ($v['value'] != $this->oldData[$k]) {
+ $moduleUpdates[$tname][$k] = $v;
+ }
+ } else {
+ // Due to how PDO's cast a boolean value False
+ // to '' when you query the DB.
+ // we need to adjust any empty fields
+ // that are of data_type boolean to a 0, True
+ // values are queried as 1.
+ // See: http://bugs.php.net/bug.php?id=33876
+ // for more info.
+ $oldData = (empty($this->oldData[$k])) ? 0 : 1;
+ if ($v['value'] != $oldData) {
+ $moduleUpdates[$tname][$k] = $v;
+ }
+ }
+ // If the field was set in the module Updates array
+ // then also try and set what type of field we are
+ // dealing w/ on the form.
+ if (isset($moduleUpdates[$tname][$k])) {
+ if ($this->elementExists($k)) {
+ $e =& $this->getElement($k);
+ if (PEAR::isError($e)) {
+ return Toolkit_Common::handleError($e);
+ }
+ $moduleUpdates[$tname][$k]['field_type'] = $e->getType();
+ }
+ }
+ }
+ }
+ }
+
+ // Need a special case for the credit cards.
+ if (is_array($values['creditCards'])) {
+ foreach ($values['creditCards'] as $k => $v) {
+ if (array_key_exists("creditCards[$k]", $this->oldData)) {
+ if ($v != $this->oldData["creditCards[$k]"]) {
+ $ccUpdates["creditCards[$k]"]['data_type'] = 'integer';
+ $ccUpdates["creditCards[$k]"]['value'] = $v;
+ }
+ } elseif (!empty($v)) {
+ $ccUpdates["creditCards[$k]"]['data_type'] = 'integer';
+ $ccUpdates["creditCards[$k]"]['value'] = $v;
+ }
+ // If the credit card was set in the credit card updates array
+ // then also try and set what type of field we are dealing w/
+ // on the form.
+ if (isset($ccUpdates["creditCards[$k]"])) {
+ if ($this->elementExists("creditCards[$k]")) {
+ $e =& $this->getElement("creditCards[$k]");
+ if (PEAR::isError($e)) {
+ return Toolkit_Common::handleError($e);
+ }
+ $ccUpdates["creditCards[$k]"]['field_type'] = $e->getType();
+ }
+ }
+ }
+ }
+ } else {
+ return parent::updateData($values);
+ }
+
+ $ccards = $values['creditCards'];
+ $pattern = '/^-?(.+)$/i';
+ $replacement = '$1';
+ // Adjust the lat/lon coordinates to negative #'s if needed
+ $coords = array('lat' => 'South', 'lon' => 'East');
+ foreach ($coords as $k => $v) {
+ if ($values["{$k}Direction"] == $v && !empty($values[$k])) {
+ $string = $values[$k];
+ $values[$k] = preg_replace($pattern, $replacement, $string);
+ $values[$k] = "-{$values[$k]}";
+ }
+ }
+ unset($values['lonDirection'],
+ $values['latDirection'],
+ $values['member_cats'],
+ $values['creditCards']
+ );
+
+ $this->tableMetaData = Toolkit_Common::getTableMetaData(
+ $this->dbh,
+ $this->tableName
+ );
+ // Check for updates in the member record.
+ // If we find any, add that field to the list of record updates
+ // along with what type of field it is in the member table.
+ // We will use the data_type field when the admin is dealing
+ // w/ the updates to determine values on boolean records and empty
+ // text field records.
+ foreach ($values as $k => $v) {
+ if (array_key_exists($k, $this->oldData)) {
+ if ($v != $this->oldData[$k]) {
+ if ($this->elementExists($k)) {
+ $e =& $this->getElement($k);
+ if (PEAR::isError($e)) {
+ return Toolkit_Common::handleError($e);
+ }
+ $recordUpdates[$k]['field_type'] = $e->getType();
+ }
+ $recordUpdates[$k]['data_type'] = $this->tableMetaData[$k];
+ $recordUpdates[$k]['value'] = $v;
+ }
+ }
+ // We need a special case for the member image. cause Its a pain
+ // in the ass.
+ if ($k == 'logo') {
+ if (!empty($v)) {
+ if (array_key_exists('old_logo_rmv', $this->oldData)) {
+ if ($v != $this->oldData['old_logo_rmv']) {
+ $recordUpdates[$k]['data_type'] = 'boolean';
+ $recordUpdates[$k]['field_type'] = 'file';
+ $recordUpdates[$k]['value'] = $v;
+ }
+ }
+ }
+ }
+ }
+
+ // Combine the update arrays for the modules and the member record
+ // into one single array. The array will hold this pattern.
+ // An array of tables that holds an array of fields that were updated
+ // [DB Table] => array
+ // (
+ // [Column Name] => array
+ // (
+ // [data_type] => boolean / text / integer
+ // [field_type] => text / select / checkbox
+ // [value] => updated value from the form.
+ // )
+ // )
+ // Make sure to only add these array's if there is update information
+ // in them.
+ $updates = array();
+ if (is_array($moduleUpdates)) {
+ $updates += $moduleUpdates;
+ }
+ if (is_array($recordUpdates)) {
+ $updates += array('member' => $recordUpdates);
+ }
+ if (is_array($ccUpdates)) {
+ $updates += array('member_ccard_type' => $ccUpdates);
+ }
+
+ try {
+ // If we have an array of updates, we need to insert all the
+ // updates into the member_updates table. This will signal that
+ // the member has pending updates that the admin needs to
+ // authorize.
+ if (!empty($updates)) {
+ // Loop through all the elements that were updated and get
+ // the label we use on the form so when the admin is looking
+ // at the updates they will know what field its for.
+ // We can be sure we are getting the right label because
+ // there can only be unique element names in the form.
+ foreach ($updates as &$sec) {
+ foreach ($sec as $field => $v) {
+ switch ($field) {
+ case 'lat' :
+ $g =& $this->getElement('latitude');
+ $e =& $g->getElements();
+ $sec[$field]['label'] = $e[1]->getLabel();
+ break;
+
+ case 'lon' :
+ $g =& $this->getElement('longitude');
+ $e =& $g->getElements();
+ $sec[$field]['label'] = $e[1]->getLabel();
+ break;
+
+ case '' :
+ case null :
+ break;
+
+ default :
+ $e =& $this->getElement($field);
+ // Check to make sure an actual element was
+ // returned. If a "module" is unassigned from a
+ // category, those elements will not be created.
+ // so we won't be able to get the labels for those
+ // elements. In this case, just use the field
+ // name.
+ if (PEAR::isError($e)) {
+ $sec [$field]['label'] = $field;
+ } else {
+ $sec[$field]['label'] = $e->getLabel();
+ }
+ break;
+ }
+ }
+ }
+ $this->dbh->beginTransaction();
+
+ $sql = "
+ INSERT INTO {$this->pendingTable} (member_id, field, update, db_table, data_type, field_type, label)
+ VALUES (:member_id, :field, :update, :table, :data_type, :field_type, :label)";
+
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $GLOBALS['memberAuth']->getAuthData('member_id'), PDO::PARAM_INT);
+ foreach ($updates as $table => &$sec) {
+ $stmt->bindParam(':table', $table, PDO::PARAM_STR);
+ foreach ($sec as $k => &$v) {
+ $dataType = PDO::PARAM_STR;
+ // Fields that are empty which have a data_type of text
+ // can be inserted as NULL values.
+ if (empty($v['value']) && $v['data_type'] == 'text') {
+ $v['value'] = null;
+ $dataType = PDO::PARAM_NULL;
+ }
+ $stmt->bindParam(":field", $k, PDO::PARAM_STR);
+ $stmt->bindParam(":update", $v['value'], $dataType);
+ $stmt->bindParam(":data_type", $v['data_type'], PDO::PARAM_STR);
+ $stmt->bindParam(":field_type", $v['field_type'], PDO::PARAM_STR);
+ $stmt->bindParam(":label", $v['label'], PDO::PARAM_STR);
+ $stmt->execute();
+ }
+ }
+ $this->setPending();
+ $this->emailOwner();
+ return $this->dbh->commit();
+ }
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+
+ return;
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/EditPackages.php b/Toolkit/Members/EditPackages.php
new file mode 100644
index 0000000..9f1cb4c
--- /dev/null
+++ b/Toolkit/Members/EditPackages.php
@@ -0,0 +1,1935 @@
+
+ * @copyright 2009 Jamie Kahgee
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: EditPackages.php,v 1.16 2010/07/18 16:45:33 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ * @see Toolkit/Image/Server.php
+ */
+
+
+/**
+ * The image server processing class
+ */
+require_once BASE . 'Toolkit/Image/Server.php';
+
+/**
+ * Constructor class to setup the page layout
+ *
+ * this class determines if the user can upload any more packages to their
+ * account and if so renders the add package form. It also controls
+ * rending the individual forms for each previously uploaded package.
+ *
+ * @category MembersDB
+ * @package Toolkit_Members
+ * @author Jamie Kahgee
$memberName
+ ');
+
+ // updated the hidden elements value to make sure it
+ // holds the most up-to-date image name
+ $e =& $this->getElement('curr_image_rmv');
+ $e->setValue($image);
+ }
+
+ // }}}
+ // {{{ uploadImage()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param Toolkit_Image_Server $is Parameter description (if any) ...
+ * @param string $field Form field name of image
+ *
+ * @return string image name
+ * @access protected
+ */
+ protected function uploadImage(Toolkit_Image_Server $is, $field)
+ {
+ return $is->imageUpload($field);
+ }
+
+ // }}}
+}
+
+/**
+ * Form to handle editing/deleting existing packages in members only area
+ *
+ * Handles updating caption requests for a member or to remove a
+ * package from thier profile
+ *
+ * @category MembersDB
+ * @package Toolkit_Members
+ * @author Jamie Kahgee
';
+ $defaults['curr_image'] = sprintf($img, MEMBER_PHOTOS . $defaults['image']);
+
+ // Get any updates for that photo that are still in
+ // a pending status.
+ $sql = "
+ SELECT *
+ FROM member_updates
+ WHERE id in (
+ SELECT max(id)
+ FROM member_updates
+ WHERE foreign_key = :foreign_key
+ AND db_table = 'member_packages'
+ GROUP BY field)";
+
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->execute(array($this->packageId));
+ while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
+ if ($row['field'] == 'title') {
+ $defaults['title'] = $row['update'];
+ } elseif ($row['field'] == 'description') {
+ $defaults['description'] = $row['update'];
+ }
+ }
+
+ $this->showCurrImg = $defaults['image'];
+ $this->setupDefaults($defaults);
+ }
+
+ // }}}
+ // {{{ configureElements()
+
+ /**
+ * Setup the elements to use on the form.
+ *
+ * @access public
+ * @see Toolkit_FormBuilder::setupElements()
+ * @return void
+ */
+ public function configureElements()
+ {
+ $e = array();
+ // All Grouped Elements are created here.
+
+ // All Elements are created here. This includes group element definitions.
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'title',
+ 'display' => 'Package Title',
+ );
+ $e[] = array(
+ 'type' => 'textarea',
+ 'req' => false,
+ 'name' => 'description',
+ 'display' => 'Package Description',
+ 'opts' => array('id' => 'descr' . $this->packageId, 'class' => 'ckeditor'),
+ 'noCharLimit' => true
+ );
+ $e[] = array(
+ 'type' => 'date',
+ 'req' => true,
+ 'name' => 'sdate',
+ 'display' => 'Start Date',
+ 'opts' => array(
+ 'format' => 'm / d / Y',
+ 'minYear' => date('Y'),
+ 'maxYear' => date('Y') + 10,
+ 'addEmptyOption' => true,
+ 'emptyOptionValue' => '',
+ 'emptyOptionText' => array(
+ 'm' => 'mm',
+ 'd' => 'dd',
+ 'Y' => 'yyyy',
+ ),
+ )
+ );
+ $e[] = array(
+ 'type' => 'date',
+ 'req' => true,
+ 'name' => 'edate',
+ 'display' => 'End Date',
+ 'opts' => array(
+ 'format' => 'm / d / Y',
+ 'minYear' => date('Y'),
+ 'maxYear' => date('Y') + 10,
+ 'addEmptyOption' => true,
+ 'emptyOptionValue' => '',
+ 'emptyOptionText' => array(
+ 'm' => 'mm',
+ 'd' => 'dd',
+ 'Y' => 'yyyy',
+ ),
+ )
+ );
+ $e[] = array(
+ 'type' => 'checkbox',
+ 'req' => false,
+ 'name' => 'remove_img_rmv',
+ 'display' => 'Remove Image',
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'curr_image',
+ 'display' => 'Current Image',
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'curr_image_rmv',
+ );
+ $e[] = array(
+ 'type' => 'file',
+ 'req' => false,
+ 'name' => 'image',
+ 'display' => 'Upload a Package Photo / Image',
+ );
+ $e[] = array(
+ 'type' => 'submit',
+ 'req' => false,
+ 'name' => 'add_rmv',
+ 'display' => 'Update Package',
+ 'opts' => array('class' => 'submit')
+ );
+ $e[] = array(
+ 'type' => 'submit',
+ 'req' => false,
+ 'name' => 'remove_rmv',
+ 'display' => 'Remove Package',
+ 'opts' => array('class' => 'submit')
+ );
+
+ $this->setupElements($e);
+ }
+
+ // }}}
+ // {{{ configureRules()
+
+ /**
+ * Configure rules for form
+ *
+ * @return void
+ * @access public
+ */
+ public function configureRules()
+ {
+ $r = array();
+
+ $checkDate = create_function('$d', '$d = implode("-", $d); return Validate::date($d, array("format" => "%n-%j-%Y"));');
+ $r[] = array(
+ 'element' => 'sdate',
+ 'message' => 'ERROR: Invalid Date!',
+ 'type' => 'callback',
+ 'format' => $checkDate,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'edate',
+ 'message' => 'ERROR: Invalid Date!',
+ 'type' => 'callback',
+ 'format' => $checkDate,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+ $r[] = array(
+ 'element' => 'image',
+ 'message' => 'ERROR: Incorrect File Type (.gif, .png, .jpg) only!',
+ 'type' => 'mimetype',
+ 'format' => $this->mimeTypes,
+ 'validation' => $this->validationType,
+ 'reset' => false,
+ 'force' => false
+ );
+
+ $this->setupRules($r);
+ }
+
+ // }}}
+ // {{{ configureConstants()
+
+ /**
+ * Configure constants for form
+ *
+ * @return void
+ * @access public
+ */
+ public function configureConstants()
+ {
+ $c = array(
+ 'remove_img_rmv' => false
+ );
+
+ $this->setupConstants($c);
+ }
+
+ // }}}
+ // {{{ configureFilters()
+
+ /**
+ * Configure filters for form
+ *
+ * @return void
+ * @access public
+ */
+ public function configureFilters()
+ {
+ $f = array();
+
+ $f[] = array(
+ 'element' => '__ALL__',
+ 'filter' => 'trim'
+ );
+
+ $this->setupFilters($f);
+ }
+
+ // }}}
+
+ // {{{ deleteImage()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param Toolkit_Image_Server $is Parameter description (if any) ...
+ * @param string $img Parameter description (if any) ...
+ *
+ * @return unknown Return description (if any) ...
+ * @access protected
+ */
+ protected function deleteImage(Toolkit_Image_Server $is, $img)
+ {
+ return $is->imageDelete($img);
+ }
+
+ // }}}
+
+ // {{{ _createPendingData()
+
+ /**
+ * Description for _createPendingData()
+ *
+ * @param array $values Value array
+ *
+ * @return void|mixed only on error
+ * @access private
+ */
+ private function _createPendingData($values)
+ {
+ try {
+ $sql = "
+ INSERT INTO member_updates
+ (field, update, db_table, data_type, label,
+ foreign_key, member_id, field_type)
+ VALUES (:field, :update, :db_table, :data_type, :label,
+ :foreign_key, :member_id, :field_type)";
+
+ $dataToInsert = array();
+ if ($values['title'] != $this->_defaultValues['title']) {
+ $dataToInsert[] = array(
+ 'field' => 'title',
+ 'update' => $values['title'],
+ 'label' => 'Title'
+ );
+ }
+
+ if ($values['description'] != $this->_defaultValues['description']) {
+ $dataToInsert[] = array(
+ 'field' => 'description',
+ 'update' => $values['description'],
+ 'label' => 'Description'
+ );
+ }
+ /*if ($values['image'] != $this->_defaultValues['image']) {
+ $dataToInsert[] = array(
+ 'field' => 'image',
+ 'update' => $values['image'],
+ 'label' => 'Image'
+ );
+ }*/
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindValue(':db_table', 'member_packages', PDO::PARAM_STR);
+ $stmt->bindValue(':data_type', 'text', PDO::PARAM_STR);
+ $stmt->bindValue(':field_type', 'text', PDO::PARAM_STR);
+ $stmt->bindParam(':foreign_key', $values['id'], PDO::PARAM_INT);
+ $stmt->bindParam(':member_id', $values['member_id'], PDO::PARAM_INT);
+
+ foreach ($dataToInsert as $i) {
+ if (!empty($i['update'])) {
+ $stmt->bindParam(':field', $i['field'], PDO::PARAM_STR);
+ $stmt->bindParam(':update', $i['update'], PDO::PARAM_STR);
+ $stmt->bindParam(':label', $i['label'], PDO::PARAM_STR);
+ $stmt->execute();
+ }
+ }
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+
+ // {{{ emailOwner()
+
+ /**
+ * Emails the owner and anyone else who wants to be advised of updates
+ *
+ * A false value in the primaryAdvisee will cause no email to be sent.
+ * all secondary advisees listed in the constructor are carbon copied
+ * in the email.
+ *
+ * Emails are sent out in both HTML and TXT forms.
+ *
+ * @return boolean result of email
+ * @access protected
+ */
+ protected function emailOwner()
+ {
+ if (MEMBER_RECORD_UPDATES_ADVISOR === false) {
+ return;
+ } else {
+ $this->flexyOptions = Toolkit_Members::getFlexyOptions();
+ $id = $GLOBALS['memberAuth']->getAuthData('member_id');
+ try {
+ $sql = "
+ SELECT member_name
+ FROM member
+ WHERE member_id = :member_id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':member_id', $id, PDO::PARAM_INT);
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ $memberName = $row['member_name'];
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ $template = new HTML_Template_Flexy($this->flexyOptions);
+ $page = new stdClass();
+ $page->member = $memberName;
+ $page->url = ($_SERVER['HTTPS'] == 'on') ? BASE_SECURE_URL : MEDIA_BASE_URL;
+ $page->email = OWNER_EMAIL;
+ $page->siteName = SITENAME;
+ $page->link = 'link';
+
+ $template->compile($this->emailTemplate);
+ // Merge the compiled template with the $page object.
+ $htmlMsg = $template->bufferedOutputObject($page);
+
+ $msg = "
+
$memberName
+ ');
+
+ // updated the hidden elements value to make sure it
+ // holds the most up-to-date image name
+ $e =& $this->getElement('curr_image_rmv');
+ $e->setValue($image);
+ }
+
+ // }}}
+ // {{{ uploadImage()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param Toolkit_Image_Server $is Parameter description (if any) ...
+ * @param string $field Parameter description (if any) ...
+ *
+ * @return string Return description (if any) ...
+ * @access protected
+ */
+ protected function uploadImage(Toolkit_Image_Server $is, $field)
+ {
+ return $is->imageUpload($field);
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/EditPhoto.php b/Toolkit/Members/EditPhoto.php
new file mode 100644
index 0000000..779b353
--- /dev/null
+++ b/Toolkit/Members/EditPhoto.php
@@ -0,0 +1,235 @@
+
+ * @copyright 2009 Jamie Kahgee
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: EditPhoto.php,v 1.5 2010/07/16 20:52:51 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ * @see Toolkit/Image/Server.php
+ */
+
+
+/**
+ * The image server processing class
+ */
+require_once BASE . 'Toolkit/Image/Server.php';
+
+/**
+ * Form to handle editing/deleting existing photos in members only area
+ *
+ * Handles updating caption requests for a member or to remove a
+ * photo from thier profile
+ *
+ * @category MembersDB
+ * @package Toolkit_Members
+ * @author Jamie Kahgee
+ * protected $email = false;
+ *
+ *
+ * @var unknown
+ * @access protected
+ */
+ protected $email;
+
+ /**
+ * From header in the owner email
+ *
+ * This just sets the From header in the owner email
+ * SITENAME header in email
+ *
+ * It gets set in the constructor if you leave empty here, but you
+ * can set it to something different here to override that if you desire.
+ *
+ * @var string
+ * @access protected
+ */
+ protected $subject = 'New Event Submission';
+
+ /**
+ * Message to display if the form is successfully submitted
+ *
+ * @var string
+ * @access protected
+ */
+ protected $successMsg = '
+
+
'.print_r($daysOw, true).'
';
+ $e[] = array(
+ 'type' => 'group',
+ 'req' => false,
+ 'name' => 'daysow',
+ 'group' => $daysOw,
+ 'label' => 'Days Of Week',
+ 'seperator' => ' ',
+ 'appendName' => true
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => true,
+ 'name' => 'category',
+ 'display' => 'Category',
+ 'opts' => $this->getTopicFields(),
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'website',
+ 'display' => 'Website'
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'facebook',
+ 'display' => 'Facebook',
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'twitter',
+ 'display' => 'Twitter',
+ );
+
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'cost',
+ 'display' => 'Cost',
+ );
+ $e[] = array(
+ 'type' => 'textarea',
+ 'req' => false,
+ 'name' => 'intro',
+ 'display' => 'Intro 350 characters left',
+ 'opts' => array('id' => 'intro')
+ );
+ $e[] = array(
+ 'type' => 'textarea',
+ 'req' => false,
+ 'name' => 'description',
+ 'display' => 'Description',
+ 'opts' => array('id' => 'descr')
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'current_img_rmv',
+ 'display' => 'Current Image'
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'img'
+ );
+ $e[] = array(
+ 'type' => 'file',
+ 'req' => false,
+ 'name' => 'img_file_rmv',
+ 'display' => 'Event Image'
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'img_instructions_rmv',
+ 'opts' => '.jpg or .gif images only'
+ );
+ $e[] = array(
+ 'type' => 'header',
+ 'name' => 'eventLocationInfoHeader_rmv',
+ 'display' => 'Event Location Information
+
+
+ Delete Image?'
+ : 'Image not yet uploaded';
+ $ri = 1;
+ for ($r = 1; $r <= 7; ++$r) {
+ if ($d['daysow']&$ri) {
+ $daysow[$r] = $ri;
+ }
+ $ri = $ri << 1;
+ }
+ $d['daysow'] = $daysow;
+ } else {
+ $d['current_img_rmv'] = 'Image not yet uploaded';
+ $d['current_file_rmv'] = 'File not yet uploaded';
+ }
+ $d['member'] = $GLOBALS['memberAuth']->getAuthData('member_id');
+ $this->setupDefaults($d);
+ }
+
+ // }}}
+
+ // {{{ emailOwner()
+
+ /**
+ * Emails the owner the submitted data from the submitted form
+ *
+ * Uses a flexy template to render a nice looking html email.
+ * Fills in the supplied data from the form and doesn't add the
+ * empty fields the user didn't fill in.
+ *
+ * @param string $mailFactory What type of mail factory should we use
+ *
+ * @return boolean result of the mailing
+ * @access protected
+ */
+ protected function emailOwner($mailFactory = 'mail')
+ {
+ if (!$this->email) {
+ return;
+ }
+
+ $topics = $this->getTopicFields();
+ $template = new HTML_Template_Flexy($this->flexyOptions);
+ $page = new stdClass();
+
+ $page->email_from = OWNER_EMAIL;
+ $page->subject = $this->subject;
+ $page->client_info = $this->clientInfo;
+ $page->fname = $this->_getMemberName();
+ $page->formData = $this->formData;
+ // setup a link to admin section
+ $page->lname
+ = 'Events Admin';
+ unset(
+ $page->formData['img'],
+ $page->formData['member_id'],
+ $page->formData['MAX_FILE_SIZE'],
+ $page->formData['comments'],
+ $page->formData['visable'],
+ $page->formData['id']
+ );
+ if ($page->formData['btime']['element']) {
+ $btime = explode(" / ", $page->formData['btime']['element']);
+ $page->formData['btime']['element']
+ = $btime[0] . ':' . (($btime[1] == '0')?'00':$btime[1]) . ' ' . $btime[2];
+ }
+ if ($page->formData['etime']['element']) {
+ $etime = explode(" / ", $page->formData['etime']['element']);
+ $page->formData['etime']['element']
+ = $etime[0] . ':' . (($etime[1] == '0')?'00':$etime[1]) . ' ' . $etime[2];
+ }
+ if ($page->formData['topicid']['element']) {
+ // Clean up the mail_ok flag so its human readable
+ $page->formData['topicid']['element']
+ = $topics[$page->formData['topicid']['element']];
+ }
+
+ $template->compile('emailOwner.tpl');
+ $htmlMsg = $template->bufferedOutputObject($page);
+
+ $msg = "{$page->subject}\n\n";
+ $msg .= "From {$page->fname} {$page->lname}\n\n";
+ $msg .= "Information\n\n";
+ foreach ($page->formData as $i) {
+ $msg .= "{$i['label']}: {$i['element']}\n";
+ }
+
+ $mimeMail = new Mail_mime("\n");
+ $mimeMail->setFrom("Online Form <{$page->email_from}>");
+ $mimeMail->setSubject($this->subject);
+ $mimeMail->setHTMLBody($htmlMsg);
+ $mimeMail->setTXTBody($msg);
+
+ $mail =& Mail::factory($mailFactory);
+ $body = $mimeMail->get();
+
+ $setHeader['Reply-To'] = "{$this->getSubmitValue('fname')} {$this->getSubmitValue('lname')} <{$this->getSubmitValue('email')}>";
+
+ $headers = $mimeMail->headers($setHeader);
+
+ $res = $mail->send($this->email, $headers, $body);
+ if (PEAR::isError($res)) {
+ return Toolkit_Common::handleError($res);
+ } else {
+ return $res;
+ }
+ }
+
+ // }}}
+
+ // {{{ _getMemberName()
+ /**
+ * return the member name from PDO call
+ *
+ * @access protected
+ * @return string
+ */
+ function _getMemberName()
+ {
+ try {
+ $sql = "
+ SELECT member_name
+ FROM member
+ WHERE member_id = :mid";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(
+ ":mid",
+ $GLOBALS['memberAuth']->getAuthData('member_id'),
+ PDO::PARAM_INT
+ );
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+ // }}}
+ // {{{ getTopicFields()
+
+ /**
+ * get event topics
+ *
+ * @return array topics
+ * @access protected
+ */
+ protected function getTopicFields()
+ {
+ try {
+ $sql = "
+ SELECT *
+ FROM categories
+ ORDER BY name";
+
+ $topics = array('' => '-- Select --');
+ foreach ($this->dbh->query($sql) as $row) {
+ $topics[$row['id']] = $row['name'];
+ }
+
+ return $topics;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ hasEndDate()
+
+ /**
+ * verifies if we have a valid end date to work with
+ *
+ * @param string $d end date
+ *
+ * @return boolean if the end date is
+ */
+ protected function hasEndDate($d)
+ {
+ $pattern = '/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/';
+ if (preg_match($pattern, $d, $m)) {
+ return checkdate((int) $m[1], (int) $m[2], (int) $m[3]);
+ } else {
+ return false;
+ }
+ }
+
+ // }}}
+
+ // {{{ formatValue()
+
+ /**
+ * Format an array into an acceptable string
+ *
+ * @param mixed &$i array values to format or null value for
+ * element that was not filled in
+ * @param string $format string to format values into
+ *
+ * @return string formatted string
+ * @access public
+ */
+ public function formatValue(&$i, $format)
+ {
+ // Allow for 0 to be not empty. This allows for minutes in the
+ // time arrays to be valid if they are on the hour ie. (1:00 pm)
+ $notEmpty = create_function('$v', 'return strlen($v) > 0;');
+ if (is_array($i) && count(array_filter($i, $notEmpty)) == 3) {
+ list($x, $y, $z) = array_values($i);
+ eval("\$i = sprintf('$format', $x, $y, $z);");
+ } else {
+ $i = null;
+ }
+ }
+
+ // }}}
+
+ // {{{ insertData()
+
+ /**
+ * Inserts contact data into the contact db
+ *
+ * @param array $values submitted values
+ *
+ * @return object result of db insert query
+ * @access protected
+ */
+ protected function insertData($values)
+ {
+ $values = $this->_geocode($values);
+
+ try {
+ // need to set the dates up first
+ unset($values['id']);
+ $values['visable'] = 0;
+ $sql = Toolkit_Common::createSQLInsert(
+ $this->tableName,
+ array_keys($values)
+ );
+ $sql .= " RETURNING id";
+ $stmt = Toolkit_Common::prepareQuery(
+ $this->dbh,
+ $this->tableName,
+ $sql,
+ $values
+ );
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ private function _geocode(array $values)
+ {
+ $geocoder = new GeocodeYahoo();
+ if (!$values['address'] && !$values['city'] && !$values['state']) {
+ return $values;
+ }
+ $address = array(
+ 'city' => $values['city'],
+ 'state' => $values['state'],
+ 'zip' => $values['zip'],
+ );
+ if (!empty($values['address'])) {
+ $address['street'] = $values['address'];
+ }
+ try {
+ $response = $geocoder->geocodeAddress($address);
+ $responseArray = unserialize($response);
+ if ($responseArray['ResultSet']['Result'][0]['Latitude']) {
+ $values['lat'] = $responseArray['ResultSet']['Result'][0]['Latitude'];
+ $values['lon'] = $responseArray['ResultSet']['Result'][0]['Longitude'];
+ } else {
+ $values['lat'] = $responseArray['ResultSet']['Result']['Latitude'];
+ $values['lon'] = $responseArray['ResultSet']['Result']['Longitude'];
+ }
+ } catch (BadMethodCallException $e) {
+ Toolkit_Logger::logException('Invalid Arg', $e);
+ } catch (Exception $e) {
+ Toolkit_Logger::logException('Yahoo GeoCode', $e);
+ }
+ return $values;
+ }
+
+ // {{{ 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();
+ $this->setFormData($e);
+
+ if ( (!$this->_didLatLonChange($values)
+ && $this->_didAddressChange($values))
+ || (!$values['lat'] && !$values['lon'])
+ ) {
+ $values = $this->_geocode($values);
+ }
+ unset($values['MAX_FILE_SIZE']);
+ if ($values['del_img_rmv'] && $values['img']) {
+ $is = new Toolkit_Image_Server();
+ $is->imageDelete($values['img']);
+ $values['image'] = '';
+ }
+ if ($values['img']) {
+ $values['image'] = $values['img'];
+ }
+ if ($values['del_file_rmv'] && $values['file']) {
+ $is = new Toolkit_Image_Server();
+ $is->imageDelete($values['file']);
+ $values['file'] = '';
+ }
+ if ($values['file_rmv']['name']) {
+ $fs = new Toolkit_FileServer_FileAdapter();
+ try {
+ $res = $fs->upload('file_rmv');
+ } catch (Toolkit_FileServer_Exception $e) {
+ Toolkit_Logger::logException('File Server', $e);
+ echo -1;
+ return;
+ }
+ $values['file'] = $res['name'];
+ }
+ if ($values['file']) {
+ $newFile = EventFile::createByValues(
+ array(
+ 'filename' => $values['file'],
+ 'urltext' => $values['filename']
+ )
+ );
+ $values['files'] = array($newFile);
+ } else {
+ $values['files'] = array();
+ }
+ unset($values['file']);
+ unset($values['filename']);
+ // Get rid of any defined un-needed elements.
+ // un-needed elements after the form is submitted are defined
+ // by the ending _rmv name.
+ foreach ($values as $k => &$v) {
+ if (!is_array($v)) {
+ $values[$k] = preg_replace("/\r/", "\n", $v);
+ }
+ if (preg_match('/^.+_rmv$/', $k)) {
+ unset($values[$k]);
+ }
+ }
+
+ if ($values['recurr']) {
+ if ($values['dayom']) {
+ $values['weekom'] = null;
+ $values['daysow'] = null;
+ } else {
+ $values['dayom'] = null;
+ $values['daysow'] = array_sum($values['daysow']);
+ }
+
+ } else {
+ $values['dayom'] = null;
+ $values['weekom'] = null;
+ $values['daysow'] = null;
+ }
+ $bdate = $values['bdate'];
+ $edate = $values['edate'];
+ $this->formatValue($values['btime'], '%d:%02d %s');
+ $this->formatValue($values['etime'], '%d:%02d %s');
+ if ($values['reacur']) {
+ $recur['dow'] = $values['daysow'];
+ $recur['dom'] = $values['dayom'];
+ if ($recur['dow']) {
+ $recur['recur_week'] = ($values['weekom']) ? $values['weekom'] :null;
+ } else {
+ $recur['recur_week'] = null;
+ }
+ }
+ $eventId = filter_var($_REQUEST['id'], FILTER_VALIDATE_INT);
+ if ($values['btime']) {
+ $values['starthour'] = $values['btime'];
+ } else {
+ $values['starthour'] = null;
+ }
+ unset($values['btime']);
+ if ($values['etime']) {
+ $values['endhour'] = $values['etime'];
+ } else {
+ $values['endhour'] = null;
+ }
+ unset($values['etime']);
+ if ($values['category']) {
+ $values['category'] = $this->eventMapper->fetchCategory(
+ $values['category']
+ );
+ }
+ $event = MemberEvent::createByValues($values);
+// var_dump($event);
+// var_dump($values);
+// exit;
+ return $this->eventMapper->saveEvent($event);
+
+// return true;
+ }
+
+ // }}}
+
+ // {{{ setupRenderers()
+
+ /**
+ * Custom rendering templates for special fields on the form
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ parent::setupRenderers();
+ $renderer =& $this->defaultRenderer();
+ $required = '*
+ ';
+ $error = '
+ ';
+ $renderer->setElementTemplate($recurTmpl, 'dayom');
+ $renderer->setElementTemplate($recurTmpl, 'weekom');
+ $renderer->setElementTemplate($recurTmpl, 'daysow');
+ $renderer->setElementTemplate(
+ ''.$required.'
+ '.$error.'{element} ',
+ 'description'
+ );
+ $renderer->setElementTemplate(
+ ''.$required.'{label}'
+ .$error.'{element} ', 'submit_rmv'
+ );
+ }
+
+ // }}}
+
+ // {{{ 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.
+ *
+ * @return string form HTML state
+ * @access public
+ */
+ public function toHtml()
+ {
+ $GLOBALS['topScripts'][] = JQUERY_CDN_JS;
+ $GLOBALS['bottomScripts'][] = MEDIA_APP_BASE_URL . 'libjs/textlimit.js';
+ $baseSecureUrl
+ = ($_SERVER['HTTPS'] == 'on')
+ ? BASE_SECURE_URL
+ : MEDIA_BASE_URL;
+ $appBaseSecureUrl
+ = ($_SERVER['HTTPS'] == 'on')
+ ? GLM_APP_BASE_SECURE_URL
+ : MEDIA_APP_BASE_URL;
+ $GLOBALS['topScripts'][]
+ = $appBaseSecureUrl
+ . 'libjs/jqueryui/1.8.13/js/jquery-ui-1.8.13.custom.min.js';
+ $GLOBALS['topScripts'][] = CKEDITOR_JS.'';
+
+ $this->setupRenderers();
+ if ($this->validate()) {
+ $this->cleanForm();
+
+ if ($this->process(array(&$this, 'processData'), $this->mergeFiles)) {
+ $this->freeze();
+ $this->emailOwner();
+ $output = $this->successMsg;
+ header(
+ 'Location: ' . MEDIA_BASE_URL . "members-only-area/?rt=CommonEvents&page_id="
+ . $_REQUEST['page_id']
+ );
+ exit;
+ }
+ $this->sent = true;
+ } elseif ($this->isSubmitted()) {
+ $output = $this->errorMsg;
+ $GLOBALS['topScripts'][]
+ = 'http://maps.googleapis.com/maps/api/js?sensor=true';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Maps/geoCoder.js';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Events/libjs/edit-event.js';
+ $output .= parent::toHtml();
+ } else {
+ $GLOBALS['topScripts'][]
+ = 'http://maps.googleapis.com/maps/api/js?sensor=true';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Maps/geoCoder.js';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Events/libjs/edit-event.js';
+ $output = parent::toHtml();
+ }
+ return $output;
+ }
+
+ // }}}
+ /**
+ * check to see if the address (old on) is different than the one submitted
+ * if the event is not found then return false
+ *
+ * @param array $values The submitted values for the edit event form
+ *
+ * @return boolean
+ */
+ private function _didAddressChange($values)
+ {
+ $didAddressChange = false;
+ if (!$values['id'] && !ctype_digit($values['id'])) {
+ return $didAddressChange;
+ }
+ try {
+ $sql = "
+ SELECT address,city,state,zip
+ FROM events.events
+ WHERE id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $values['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ $address = $stmt->fetch(PDO::FETCH_ASSOC);
+ if (!$address) {
+ return $didAddressChange;
+ } else {
+ if ($address['address'] != $values['address']) {
+ $didAddressChange = true;
+ }
+ if ($address['city'] != $values['city']) {
+ $didAddressChange = true;
+ }
+ if ($address['state'] != $values['state']) {
+ $didAddressChange = true;
+ }
+ if ($address['zip'] != $values['zip']) {
+ $didAddressChange = true;
+ }
+ }
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ return $didAddressChange;
+ }
+ private function _didLatLonChange($values)
+ {
+ $didLatLonChange = false;
+ if (!$values['id'] && !ctype_digit($values['id'])) {
+ return $didLatLonChange;
+ }
+ try {
+ $sql = "
+ SELECT lat,lon
+ FROM events.events
+ WHERE id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $values['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ $location = $stmt->fetch(PDO::FETCH_ASSOC);
+ if (!$location) {
+ return $didLatLonChange;
+ } else {
+ if ($location['lat'] != $values['lat']) {
+ $didLatLonChange = true;
+ }
+ if ($location['lon'] != $values['lon']) {
+ $didLatLonChange = true;
+ }
+ }
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ return $didLatLonChange;
+ }
+ // {{{ updateData()
+
+ /**
+ * Inserts contact data into the contact db
+ *
+ * @param array $values submitted values
+ *
+ * @return object result of db insert query
+ * @access protected
+ */
+ protected function updateData($values)
+ {
+ try {
+ // if the address changes then get the lat lon
+ if ( (!$this->_didLatLonChange($values)
+ && $this->_didAddressChange($values))
+ || (!$values['lat'] && !$values['lon'])
+ ) {
+ $values = $this->_geocode($values);
+ }
+
+ $sql = Toolkit_Common::createSQLUpdate(
+ $this->tableName,
+ array_keys($values),
+ array('id = :id')
+ );
+
+ return Toolkit_Common::processQuery(
+ $this->dbh,
+ $this->tableName,
+ $sql,
+ $values
+ );
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ getTimeStamp()
+ /**
+ * getTimeStamp
+ *
+ * @param mixed $MySqlDate Description of $MySqlDate
+ *
+ * @access public
+ * @return void
+ */
+ function getTimeStamp($MySqlDate)
+ {
+ $date_array = explode("-", $MySqlDate); // split the array
+ $var_year = $date_array[0];
+ $var_month = $date_array[1];
+ $var_day = $date_array[2];
+ $var_timestamp = mktime(0, 0, 0, $var_month, $var_day, $var_year);
+ return $var_timestamp; // return it to the user
+ }// }}}
+ // {{{ ordinalDay()
+ /**
+ * ordinalDay
+ *
+ * @param mixed $ord Ord
+ * @param mixed $day Day
+ * @param mixed $month Month
+ * @param mixed $year Year
+ *
+ * @access public
+ * @return void
+ */
+ function ordinalDay($ord, $day, $month, $year)
+ {
+ $firstOfMonth = mktime(0, 0, 30, $month, 1, $year);
+ $lastOfMonth = $firstOfMonth + date("t", $firstOfMonth) * 86400;
+ $dayOccurs = 0;
+
+ for ($i = $firstOfMonth; $i < $lastOfMonth ; $i += 86400) {
+ if (date("w", $i) == $day) {
+ $dayOccurs++;
+ if ($dayOccurs == $ord) {
+ $ordDay = $i;
+ }
+ }
+ }
+ return $ordDay;
+ }// }}}
+ // {{{ getEventDates()
+ /**
+ * getEventDates
+ *
+ * @param mixed $starttime Start time
+ * @param mixed $endtime End time
+ * @param mixed $recur Recur
+ * @param string $format Format
+ *
+ * @access public
+ * @return void
+ */
+ function getEventDates($starttime, $endtime, $recur, $format = 'm/d/Y')
+ {
+ if (!is_array($recur)) {
+ return;
+ }
+ if ($starttime == $endtime) {
+ return;
+ }
+ if (is_array($recur['dow'])) {
+ $daysow = array_sum($recur['dow']);
+ }
+ if ($recur['recur_week'] == 9) {
+ $fWeekNum = date("W", $starttime);
+ if (date('w', $starttime) == 0) {
+ $fWeekNum++;
+ }
+ $lWeekNum = date("W", $endtime);
+ if (date('w', $endtime) == 0) {
+ $lWeekNum++;
+ }
+ for ($fi = $fWeekNum; $fi <= $lWeekNum; $fi = $fi + 2) {
+ $eWeeks[] = $fi;
+ }
+ }
+ for ($i = $starttime; $i <= $endtime; $i += 86400) {
+ if ($recur['recur_week'] != '') {
+ if ($daysow) {
+ $ri = 1;
+ for ($r=0;$r<7;$r++) {
+ if ($daysow & $ri) {
+ $ord = $this->ordinalDay($recur['recur_week'], $r, date('n', $i), date('Y', $i));
+ }
+ $ri = $ri << 1;
+ }
+ } else {
+ $ord = null;
+ }
+ } else {
+ $ord = null;
+ }
+ if ($recur['dom']) {
+ if (date("j", $i) == $recur['dom']) {
+ $events[] = date($format, $i);
+ }
+ } elseif (is_array($recur['dow'])) {
+ $cur_dow = date("w", $i);
+ switch ($cur_dow) {
+ case 0:
+ $cur_dow = 1;
+ break;
+ case 1:
+ $cur_dow = 2;
+ break;
+ case 2:
+ $cur_dow = 4;
+ break;
+ case 3:
+ $cur_dow = 8;
+ break;
+ case 4:
+ $cur_dow = 16;
+ break;
+ case 5:
+ $cur_dow = 32;
+ break;
+ case 6:
+ $cur_dow = 64;
+ break;
+ }
+ if ((int)$cur_dow & $daysow) {
+ $cDateWeek = date("W", $i);
+ if (date('w', $time) == 0) {
+ $cDateWeek++;
+ }
+ if ($recur['recur_week'] == 9) {
+ if (in_array($cDateWeek, $eWeeks)) {
+ $events[] = date($format, $i);
+ }
+ } elseif ($recur['recur_week'] != '') {
+ if ($recur['recur_week'] && $i && $ord) {
+ if ($i == $ord) {
+ $events[] = date($format, $i);
+ }
+ }
+ } else {
+ $events[] = date($format, $i);
+ }
+ }
+ }
+ }
+ return $events;
+ }// }}}
+}
diff --git a/Toolkit/Members/Events/EditEvent.php b/Toolkit/Members/Events/EditEvent.php
new file mode 100755
index 0000000..e4c2127
--- /dev/null
+++ b/Toolkit/Members/Events/EditEvent.php
@@ -0,0 +1,1664 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: AddEventForm.php,v 1.20 2010/07/04 23:58:22 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ */
+
+require_once BASE . 'Toolkit/Forms/Rules/Image.php';
+
+/**
+ * Toolkit_Members_Events_EditEvent
+ *
+ * @category Toolkit
+ * @package Members_Events
+ * @author Steve Sutton '
+ .$required.'{label}'.$error.'{element}
+ * protected $email = false;
+ *
+ *
+ * @var unknown
+ * @access protected
+ */
+ protected $email;
+
+ /**
+ * From header in the owner email
+ *
+ * This just sets the From header in the owner email
+ * SITENAME header in email
+ *
+ * It gets set in the constructor if you leave empty here, but you
+ * can set it to something different here to override that if you desire.
+ *
+ * @var string
+ * @access protected
+ */
+ protected $subject = 'New Event Submission';
+
+ /**
+ * Message to display if the form is successfully submitted
+ *
+ * @var string
+ * @access protected
+ */
+ protected $successMsg = '
+
+
'.print_r($daysOw, true).'
';
+ $e[] = array(
+ 'type' => 'group',
+ 'req' => false,
+ 'name' => 'daysow',
+ 'group' => $daysOw,
+ 'label' => 'Days Of Week',
+ 'seperator' => ' ',
+ 'appendName' => true
+ );
+ $e[] = array(
+ 'type' => 'select',
+ 'req' => true,
+ 'name' => 'topicid',
+ 'display' => 'Category',
+ 'opts' => $this->getTopicFields(),
+ );
+ $e[] = array(
+ 'type' => 'text',
+ 'req' => false,
+ 'name' => 'url',
+ 'display' => 'Website'
+ );
+ $e[] = array(
+ 'type' => 'textarea',
+ 'req' => false,
+ 'name' => 'descr',
+ 'display' => 'Description',
+ 'opts' => array('id' => 'descr')
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'current_img_rmv',
+ 'display' => 'Current Image'
+ );
+ $e[] = array(
+ 'type' => 'hidden',
+ 'req' => false,
+ 'name' => 'img'
+ );
+ $e[] = array(
+ 'type' => 'file',
+ 'req' => false,
+ 'name' => 'img_file_rmv',
+ 'display' => 'Event Image'
+ );
+ $e[] = array(
+ 'type' => 'static',
+ 'req' => false,
+ 'name' => 'img_instructions_rmv',
+ 'opts' => '.jpg or .gif images only'
+ );
+ $e[] = array(
+ 'type' => 'header',
+ 'name' => 'eventLocationInfoHeader_rmv',
+ 'display' => 'Event Location Information
+
+
+ Delete Image?'
+ : 'Image not yet uploaded';
+ $ri = 1;
+ for ($r = 1; $r <= 7; ++$r) {
+ if ($d['daysow']&$ri) {
+ $daysow[$r] = $ri;
+ }
+ $ri = $ri << 1;
+ }
+ $d['daysow'] = $daysow;
+ } else {
+ $d['current_img_rmv'] = 'Image not yet uploaded';
+ $d['current_file_rmv'] = 'File not yet uploaded';
+ }
+ $d['member_id'] = $GLOBALS['memberAuth']->getAuthData('member_id');
+ $this->setupDefaults($d);
+ }
+
+ // }}}
+
+ // {{{ emailOwner()
+
+ /**
+ * Emails the owner the submitted data from the submitted form
+ *
+ * Uses a flexy template to render a nice looking html email.
+ * Fills in the supplied data from the form and doesn't add the
+ * empty fields the user didn't fill in.
+ *
+ * @param string $mailFactory What type of mail factory should we use
+ *
+ * @return boolean result of the mailing
+ * @access protected
+ */
+ protected function emailOwner($mailFactory = 'mail')
+ {
+ if (!$this->email) {
+ return;
+ }
+
+ $topics = $this->getTopicFields();
+ $template = new HTML_Template_Flexy($this->flexyOptions);
+ $page = new stdClass();
+
+ $page->email_from = OWNER_EMAIL;
+ $page->subject = $this->subject;
+ $page->client_info = $this->clientInfo;
+ $page->fname = $this->_getMemberName();
+ $page->formData = $this->formData;
+ // setup a link to admin section
+ $page->lname
+ = 'Events Admin';
+ unset(
+ $page->formData['img'],
+ $page->formData['member_id'],
+ $page->formData['MAX_FILE_SIZE'],
+ $page->formData['comments'],
+ $page->formData['visable'],
+ $page->formData['id']
+ );
+ if ($page->formData['btime']['element']) {
+ $btime = explode(" / ", $page->formData['btime']['element']);
+ $page->formData['btime']['element']
+ = $btime[0] . ':' . (($btime[1] == '0')?'00':$btime[1]) . ' ' . $btime[2];
+ }
+ if ($page->formData['etime']['element']) {
+ $etime = explode(" / ", $page->formData['etime']['element']);
+ $page->formData['etime']['element']
+ = $etime[0] . ':' . (($etime[1] == '0')?'00':$etime[1]) . ' ' . $etime[2];
+ }
+ if ($page->formData['topicid']['element']) {
+ // Clean up the mail_ok flag so its human readable
+ $page->formData['topicid']['element']
+ = $topics[$page->formData['topicid']['element']];
+ }
+
+ $template->compile('emailOwner.tpl');
+ $htmlMsg = $template->bufferedOutputObject($page);
+
+ $msg = "{$page->subject}\n\n";
+ $msg .= "From {$page->fname} {$page->lname}\n\n";
+ $msg .= "Information\n\n";
+ foreach ($page->formData as $i) {
+ $msg .= "{$i['label']}: {$i['element']}\n";
+ }
+
+ $mimeMail = new Mail_mime("\n");
+ $mimeMail->setFrom("Online Form <{$page->email_from}>");
+ $mimeMail->setSubject($this->subject);
+ $mimeMail->setHTMLBody($htmlMsg);
+ $mimeMail->setTXTBody($msg);
+
+ $mail =& Mail::factory($mailFactory);
+ $body = $mimeMail->get();
+
+ $setHeader['Reply-To'] = "{$this->getSubmitValue('fname')} {$this->getSubmitValue('lname')} <{$this->getSubmitValue('email')}>";
+
+ $headers = $mimeMail->headers($setHeader);
+
+ $res = $mail->send($this->email, $headers, $body);
+ if (PEAR::isError($res)) {
+ return Toolkit_Common::handleError($res);
+ } else {
+ return $res;
+ }
+ }
+
+ // }}}
+
+ // {{{ _getMemberName()
+ /**
+ * return the member name from PDO call
+ *
+ * @access protected
+ * @return string
+ */
+ function _getMemberName()
+ {
+ try {
+ $sql = "
+ SELECT member_name
+ FROM member
+ WHERE member_id = :mid";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(
+ ":mid",
+ $GLOBALS['memberAuth']->getAuthData('member_id'),
+ PDO::PARAM_INT
+ );
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+ // }}}
+ // {{{ getTopicFields()
+
+ /**
+ * get event topics
+ *
+ * @return array topics
+ * @access protected
+ */
+ protected function getTopicFields()
+ {
+ try {
+ $sql = "
+ SELECT *
+ FROM topic
+ ORDER BY descr";
+
+ $topics = array('' => '-- Select --');
+ foreach ($this->dbh->query($sql) as $row) {
+ $topics[$row['id']] = $row['descr'];
+ }
+
+ return $topics;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ hasEndDate()
+
+ /**
+ * verifies if we have a valid end date to work with
+ *
+ * @param string $d end date
+ *
+ * @return boolean if the end date is
+ */
+ protected function hasEndDate($d)
+ {
+ $pattern = '/([0-9]{2})\/([0-9]{2})\/([0-9]{4})/';
+ if (preg_match($pattern, $d, $m)) {
+ return checkdate((int) $m[1], (int) $m[2], (int) $m[3]);
+ } else {
+ return false;
+ }
+ }
+
+ // }}}
+
+ // {{{ formatValue()
+
+ /**
+ * Format an array into an acceptable string
+ *
+ * @param mixed &$i array values to format or null value for
+ * element that was not filled in
+ * @param string $format string to format values into
+ *
+ * @return string formatted string
+ * @access public
+ */
+ public function formatValue(&$i, $format)
+ {
+ // Allow for 0 to be not empty. This allows for minutes in the
+ // time arrays to be valid if they are on the hour ie. (1:00 pm)
+ $notEmpty = create_function('$v', 'return strlen($v) > 0;');
+ if (is_array($i) && count(array_filter($i, $notEmpty)) == 3) {
+ list($x, $y, $z) = array_values($i);
+ eval("\$i = sprintf('$format', $x, $y, $z);");
+ } else {
+ $i = null;
+ }
+ }
+
+ // }}}
+
+ // {{{ insertData()
+
+ /**
+ * Inserts contact data into the contact db
+ *
+ * @param array $values submitted values
+ *
+ * @return object result of db insert query
+ * @access protected
+ */
+ protected function insertData($values)
+ {
+ $values = $this->_geocode($values);
+
+ try {
+ // need to set the dates up first
+ unset($values['id']);
+ $values['visable'] = 0;
+ $sql = Toolkit_Common::createSQLInsert(
+ $this->tableName,
+ array_keys($values)
+ );
+ $sql .= " RETURNING id";
+ $stmt = Toolkit_Common::prepareQuery(
+ $this->dbh,
+ $this->tableName,
+ $sql,
+ $values
+ );
+ $stmt->execute();
+ return $stmt->fetchColumn();
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ private function _geocode(array $values)
+ {
+ $geocoder = new GeocodeYahoo();
+ if (!$values['address'] && !$values['city'] && !$values['state']) {
+ return $values;
+ }
+ $address = array(
+ 'city' => $values['city'],
+ 'state' => $values['state'],
+ 'zip' => $values['zip'],
+ );
+ if (!empty($values['address'])) {
+ $address['street'] = $values['address'];
+ }
+ try {
+ $response = $geocoder->geocodeAddress($address);
+ $responseArray = unserialize($response);
+ if ($responseArray['ResultSet']['Result'][0]['Latitude']) {
+ $values['lat'] = $responseArray['ResultSet']['Result'][0]['Latitude'];
+ $values['lon'] = $responseArray['ResultSet']['Result'][0]['Longitude'];
+ } else {
+ $values['lat'] = $responseArray['ResultSet']['Result']['Latitude'];
+ $values['lon'] = $responseArray['ResultSet']['Result']['Longitude'];
+ }
+
+ return $values;
+ } catch (BadMethodCallException $e) {
+ Toolkit_Logger::logException('Invalid Arg', $e);
+ } catch (Exception $e) {
+ Toolkit_Logger::logException('Yahoo GeoCode', $e);
+ }
+
+ }
+
+ // {{{ 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();
+ $this->setFormData($e);
+
+ unset($values['MAX_FILE_SIZE']);
+ if ($values['del_img_rmv'] && $values['img']) {
+ $is = new Toolkit_Image_Server();
+ $is->imageDelete($values['img']);
+ $values['img'] = '';
+ }
+ if ($values['del_file_rmv'] && $values['file']) {
+ $is = new Toolkit_Image_Server();
+ $is->imageDelete($values['file']);
+ $values['file'] = '';
+ }
+ if ($values['file_rmv']['name']) {
+ $fs = new Toolkit_FileServer_FileAdapter();
+ try {
+ $res = $fs->upload('file_rmv');
+ } catch (Toolkit_FileServer_Exception $e) {
+ Toolkit_Logger::logException('File Server', $e);
+ echo -1;
+ return;
+ }
+ $values['file'] = $res['name'];
+ }
+
+ // Get rid of any defined un-needed elements.
+ // un-needed elements after the form is submitted are defined
+ // by the ending _rmv name.
+ foreach ($values as $k => &$v) {
+ if (!is_array($v)) {
+ $values[$k] = preg_replace("/\r/", "\n", $v);
+ }
+ if (preg_match('/^.+_rmv$/', $k)) {
+ unset($values[$k]);
+ }
+ }
+
+ if ($values['reacur']) {
+ if ($values['dayom']) {
+ $values['weekom'] = null;
+ $values['daysow'] = null;
+ } else {
+ $values['dayom'] = null;
+ $values['daysow'] = array_sum($values['daysow']);
+ }
+
+ } else {
+ $values['dayom'] = null;
+ $values['weekom'] = null;
+ $values['daysow'] = null;
+ }
+ $bdate = $values['bdate'];
+ $edate = $values['edate'];
+ $this->formatValue($values['btime'], '%02d:%02d %s');
+ $this->formatValue($values['etime'], '%02d:%02d %s');
+ if ($values['reacur']) {
+ $recur['dow'] = $values['daysow'];
+ $recur['dom'] = $values['dayom'];
+ if ($recur['dow']) {
+ $recur['recur_week'] = ($values['weekom']) ? $values['weekom'] :null;
+ } else {
+ $recur['recur_week'] = null;
+ }
+ }
+ $eventId = $_REQUEST['id'];
+ if (ctype_digit($eventId)) {
+ $this->updateData($values);
+ } else {
+ $eventId = $this->insertData($values);
+ }
+ $this->insertEventRecur($bdate, $edate, $eventId, $recur);
+ return true;
+ }
+
+ // }}}
+
+ // {{{ setupRenderers()
+
+ /**
+ * Custom rendering templates for special fields on the form
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRenderers()
+ {
+ parent::setupRenderers();
+ $renderer =& $this->defaultRenderer();
+ $required = '*
+ ';
+ $error = '
+ ';
+ $renderer->setElementTemplate($recurTmpl, 'dayom');
+ $renderer->setElementTemplate($recurTmpl, 'weekom');
+ $renderer->setElementTemplate($recurTmpl, 'daysow');
+ $renderer->setElementTemplate(
+ ''.$required.'
+ '.$error.'{element} ',
+ 'descr'
+ );
+ $renderer->setElementTemplate(
+ ''.$required.'{label}'
+ .$error.'{element} ', 'submit_rmv'
+ );
+ }
+
+ // }}}
+
+ // {{{ 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.
+ *
+ * @return string form HTML state
+ * @access public
+ */
+ public function toHtml()
+ {
+ $GLOBALS['topScripts'][] = JQUERY_CDN_JS;
+ $baseSecureUrl = MEDIA_BASE_URL;
+ $appBaseSecueUrl = MEDIA_APP_BASE_URL;
+ $GLOBALS['topScripts'][]
+ = $appBaseSecueUrl
+ . 'libjs/jqueryui/1.8.13/js/jquery-ui-1.8.13.custom.min.js';
+ $GLOBALS['topScripts'][] = CKEDITOR_JS.'';
+
+ $this->setupRenderers();
+ if ($this->validate()) {
+ $this->cleanForm();
+
+ if ($this->process(array(&$this, 'processData'), $this->mergeFiles)) {
+ $this->freeze();
+ $this->emailOwner();
+ $output = $this->successMsg;
+ header(
+ 'Location: ' . MEDIA_BASE_URL . "members-only-area/?rt=Events&page_id=36"
+ );
+ exit;
+ }
+ $this->sent = true;
+ } elseif ($this->isSubmitted()) {
+ $output = $this->errorMsg;
+ $GLOBALS['topScripts'][]
+ = 'http://maps.googleapis.com/maps/api/js?sensor=true';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Maps/geoCoder.js';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Events/libjs/edit-event.js';
+ $output .= parent::toHtml();
+ } else {
+ $GLOBALS['topScripts'][]
+ = 'http://maps.googleapis.com/maps/api/js?sensor=true';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Maps/geoCoder.js';
+ $GLOBALS['bottomScripts'][]
+ = MEDIA_BASE_URL . 'Toolkit/Events/libjs/edit-event.js';
+ $output = parent::toHtml();
+ }
+ return $output;
+ }
+
+ // }}}
+ /**
+ * check to see if the address (old on) is different than the one submitted
+ * if the event is not found then return false
+ *
+ * @param array $values The submitted values for the edit event form
+ *
+ * @return boolean
+ */
+ private function _didAddressChange($values)
+ {
+ $didAddressChange = false;
+ if (!$values['id'] && !ctype_digit($values['id'])) {
+ return $didAddressChange;
+ }
+ try {
+ $sql = "
+ SELECT address,city,state,zip
+ FROM event
+ WHERE id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $values['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ $address = $stmt->fetch(PDO::FETCH_ASSOC);
+ if (!$address) {
+ return $didAddressChange;
+ } else {
+ if ($address['address'] != $values['address']) {
+ $didAddressChange = true;
+ }
+ if ($address['city'] != $values['city']) {
+ $didAddressChange = true;
+ }
+ if ($address['state'] != $values['state']) {
+ $didAddressChange = true;
+ }
+ if ($address['zip'] != $values['zip']) {
+ $didAddressChange = true;
+ }
+ }
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ return $didAddressChange;
+ }
+ private function _didLatLonChange($values)
+ {
+ $didLatLonChange = false;
+ if (!$values['id'] && !ctype_digit($values['id'])) {
+ return $didLatLonChange;
+ }
+ try {
+ $sql = "
+ SELECT lat,lon
+ FROM event
+ WHERE id = :id";
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':id', $values['id'], PDO::PARAM_INT);
+ $stmt->execute();
+ $location = $stmt->fetch(PDO::FETCH_ASSOC);
+ if (!$location) {
+ return $didLatLonChange;
+ } else {
+ if ($location['lat'] != $values['lat']) {
+ $didLatLonChange = true;
+ }
+ if ($location['lon'] != $values['lon']) {
+ $didLatLonChange = true;
+ }
+ }
+ } catch(PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ return $didLatLonChange;
+ }
+ // {{{ updateData()
+
+ /**
+ * Inserts contact data into the contact db
+ *
+ * @param array $values submitted values
+ *
+ * @return object result of db insert query
+ * @access protected
+ */
+ protected function updateData($values)
+ {
+ try {
+ // if the address changes then get the lat lon
+ if ( (!$this->_didLatLonChange($values)
+ && $this->_didAddressChange($values))
+ || (!$values['lat'] && !$values['lon'])
+ ) {
+ $values = $this->_geocode($values);
+ }
+
+ $sql = Toolkit_Common::createSQLUpdate(
+ $this->tableName,
+ array_keys($values),
+ array('id = :id')
+ );
+
+ return Toolkit_Common::processQuery(
+ $this->dbh,
+ $this->tableName,
+ $sql,
+ $values
+ );
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ getTimeStamp()
+ /**
+ * getTimeStamp
+ *
+ * @param mixed $MySqlDate Description of $MySqlDate
+ *
+ * @access public
+ * @return void
+ */
+ function getTimeStamp($MySqlDate)
+ {
+ $date_array = explode("-", $MySqlDate); // split the array
+ $var_year = $date_array[0];
+ $var_month = $date_array[1];
+ $var_day = $date_array[2];
+ $var_timestamp = mktime(0, 0, 0, $var_month, $var_day, $var_year);
+ return $var_timestamp; // return it to the user
+ }// }}}
+ // {{{ ordinalDay()
+ /**
+ * ordinalDay
+ *
+ * @param mixed $ord Ord
+ * @param mixed $day Day
+ * @param mixed $month Month
+ * @param mixed $year Year
+ *
+ * @access public
+ * @return void
+ */
+ function ordinalDay($ord, $day, $month, $year)
+ {
+ $firstOfMonth = mktime(0, 0, 30, $month, 1, $year);
+ $lastOfMonth = $firstOfMonth + date("t", $firstOfMonth) * 86400;
+ $dayOccurs = 0;
+
+ for ($i = $firstOfMonth; $i < $lastOfMonth ; $i += 86400) {
+ if (date("w", $i) == $day) {
+ $dayOccurs++;
+ if ($dayOccurs == $ord) {
+ $ordDay = $i;
+ }
+ }
+ }
+ return $ordDay;
+ }// }}}
+ // {{{ getEventDates()
+ /**
+ * getEventDates
+ *
+ * @param mixed $starttime Start time
+ * @param mixed $endtime End time
+ * @param mixed $recur Recur
+ * @param string $format Format
+ *
+ * @access public
+ * @return void
+ */
+ function getEventDates($starttime, $endtime, $recur, $format = 'm/d/Y')
+ {
+ if (!is_array($recur)) {
+ return;
+ }
+ if ($starttime == $endtime) {
+ return;
+ }
+ if (is_array($recur['dow'])) {
+ $daysow = array_sum($recur['dow']);
+ }
+ if ($recur['recur_week'] == 9) {
+ $fWeekNum = date("W", $starttime);
+ if (date('w', $starttime) == 0) {
+ $fWeekNum++;
+ }
+ $lWeekNum = date("W", $endtime);
+ if (date('w', $endtime) == 0) {
+ $lWeekNum++;
+ }
+ for ($fi = $fWeekNum; $fi <= $lWeekNum; $fi = $fi + 2) {
+ $eWeeks[] = $fi;
+ }
+ }
+ for ($i = $starttime; $i <= $endtime; $i += 86400) {
+ if ($recur['recur_week'] != '') {
+ if ($daysow) {
+ $ri = 1;
+ for ($r=0;$r<7;$r++) {
+ if ($daysow & $ri) {
+ $ord = $this->ordinalDay($recur['recur_week'], $r, date('n', $i), date('Y', $i));
+ }
+ $ri = $ri << 1;
+ }
+ } else {
+ $ord = null;
+ }
+ } else {
+ $ord = null;
+ }
+ if ($recur['dom']) {
+ if (date("j", $i) == $recur['dom']) {
+ $events[] = date($format, $i);
+ }
+ } elseif (is_array($recur['dow'])) {
+ $cur_dow = date("w", $i);
+ switch ($cur_dow) {
+ case 0:
+ $cur_dow = 1;
+ break;
+ case 1:
+ $cur_dow = 2;
+ break;
+ case 2:
+ $cur_dow = 4;
+ break;
+ case 3:
+ $cur_dow = 8;
+ break;
+ case 4:
+ $cur_dow = 16;
+ break;
+ case 5:
+ $cur_dow = 32;
+ break;
+ case 6:
+ $cur_dow = 64;
+ break;
+ }
+ if ((int)$cur_dow & $daysow) {
+ $cDateWeek = date("W", $i);
+ if (date('w', $time) == 0) {
+ $cDateWeek++;
+ }
+ if ($recur['recur_week'] == 9) {
+ if (in_array($cDateWeek, $eWeeks)) {
+ $events[] = date($format, $i);
+ }
+ } elseif ($recur['recur_week'] != '') {
+ if ($recur['recur_week'] && $i && $ord) {
+ if ($i == $ord) {
+ $events[] = date($format, $i);
+ }
+ }
+ } else {
+ $events[] = date($format, $i);
+ }
+ }
+ }
+ }
+ //echo ''
+ .$required.'{label}'.$error.'{element} '.print_r($events, true).'
';exit;
+ return $events;
+ }// }}}
+ // {{{ insertEventRecur()
+ /**
+ * Description of insertEventRecur()
+ *
+ * @param date $bdate Description of $bdate
+ * @param date $edate Description of $edate
+ * @param int $event_id Description of $event_id
+ * @param array $recur Description of $recur
+ *
+ * @return void
+ * @access public
+ */
+ function insertEventRecur($bdate, $edate, $event_id, $recur)
+ {
+ try {
+ $sql = "
+ DELETE
+ FROM event_recur
+ WHERE event_id = :event_id";
+ $del = $this->dbh->prepare($sql);
+ $del->bindParam(":event_id", $event_id, PDO::PARAM_INT);
+ $del->execute();
+ } catch(PDOException $e) {
+ die($e->getMessage());
+ }
+
+ if (isset($recur) && is_array($recur)) {
+ $eventDates = $this->getEventDates(
+ strtotime($bdate),
+ strtotime($edate),
+ $recur
+ );
+ $fields = array('event_id', 'event_day');
+ $sql = Toolkit_Common::createSQLInsert(
+ 'event_recur',
+ $fields
+ );
+ try {
+ if (isset($eventDates) && is_array($eventDates)) {
+ foreach ($eventDates as $eventDay) {
+ $eventValues = array(
+ 'event_id' => $event_id,
+ 'event_day' => $eventDay
+ );
+ $stmt = Toolkit_Common::prepareQuery(
+ $this->dbh,
+ 'event_recur',
+ $sql,
+ $eventValues
+ );
+ $stmt->execute();
+ }
+ }
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }
+ }
+ // }}}
+}
diff --git a/Toolkit/Members/Events/templates/emailOwner.tpl b/Toolkit/Members/Events/templates/emailOwner.tpl
new file mode 100755
index 0000000..bebee85
--- /dev/null
+++ b/Toolkit/Members/Events/templates/emailOwner.tpl
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+
+
+
+
+ {foreach:formData,v}
+
+
+
+ {end:}
+
+
+ {v[label]:h}
+
+
+ {if:v[nowrap]}
+
+ {v[element]:h}
+
+ {else:}
+
+ {v[element]:h}
+
+ {end:}
+
+ To select more than one field, hold down the CTRL key
+ while selecting items.'
+ );
+ $e[] = array(
+ 'type' => 'elementGrid',
+ 'req' => false,
+ 'name' => 'conversions',
+ 'display' => 'Field Conversions',
+ 'opts' => array('actAsGroup' => true)
+ );
+ $e[] = array(
+ 'type' => 'group',
+ 'req' => false,
+ 'name' => 'control_buttons',
+ 'group' => $prevNext,
+ 'label' => '',
+ 'seperator' => ' ',
+ 'appendName' => false
+ );
+
+ $this->setupElements($e);
+ $this->configureElementGrid(
+ 'conversions',
+ $gridColNames,
+ $tables,
+ $columns,
+ $cols
+ );
+ }
+
+ // }}}
+ // {{{ configureFilters()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function configureFilters()
+ {
+ $f = array();
+
+ $f[] = array(
+ 'element' => '__ALL__',
+ 'filter' => 'trim',
+ );
+
+ $this->setupFilters($f);
+ }
+
+ // }}}
+ // {{{ configureElementGrid()
+
+
+ /**
+ * Short description for configureElementGrid()
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $eName Parameter description (if any) ...
+ * @param unknown $colNames Parameter description (if any) ...
+ * @param unknown $tables Parameter description (if any) ...
+ * @param unknown $columns Parameter description (if any) ...
+ * @param array $cols Parameter description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function configureElementGrid(
+ $eName,
+ $colNames,
+ $tables,
+ $columns,
+ $cols
+ ) {
+ $e =& $this->getElement($eName);
+ $e->setColumnNames($colNames);
+ foreach ($cols as $i) {
+ unset($rec);
+
+ $rec[] =& $this->createElement(
+ 'static',
+ null,
+ null,
+ $i
+ );
+
+ $rec[] =& $this->createElement(
+ 'static',
+ null,
+ null,
+ ' > '
+ );
+
+ $select =& $this->createElement(
+ 'hierSelect',
+ $i
+ );
+ $select->setOptions(
+ array(
+ $tables,
+ $columns,
+ )
+ );
+ $rec[] = $select;
+
+ $rec[] =& $this->createElement(
+ 'text',
+ "{$i}_group"
+ );
+
+ $e->addRow(&$rec, ' ');
+ }
+ }
+
+ // }}}
+ // {{{ getAvailableTables()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param PDO $dbh Databse handler
+ *
+ * @return array $tables
+ * @access protected
+ */
+ protected function getAvailableTables(PDO $dbh)
+ {
+ try {
+ $sql = "
+ SELECT table_name
+ FROM information_schema.tables
+ WHERE table_type = 'BASE TABLE'
+ AND table_schema NOT IN ('pg_catalog',
+ 'information_schema')
+ ORDER BY table_name";
+
+ $tables = array();
+ foreach ($dbh->query($sql) as $i) {
+ $tables[$i['table_name']] = $i['table_name'];
+ }
+ return $tables;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+ // {{{ getTableColumns()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param PDO $dbh Database handler
+ * @param string $table Parameter description (if any) ...
+ *
+ * @return array $cols
+ * @access protected
+ */
+ protected function getTableColumns(PDO $dbh, $table)
+ {
+ try {
+ $sql = "
+ SELECT column_name
+ FROM information_schema.columns
+ WHERE table_name = '$table'
+ ORDER BY column_name";
+
+ $cols = array('' => '-- Select --');
+ foreach ($dbh->query($sql) as $i) {
+ $cols[$i['column_name']] = $i['column_name'];
+ }
+ return $cols;
+ } catch (PDOException $e) {
+ return Toolkit_Common::handleError($e);
+ }
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/Import/DBPage.php b/Toolkit/Members/Import/DBPage.php
new file mode 100644
index 0000000..c8f692a
--- /dev/null
+++ b/Toolkit/Members/Import/DBPage.php
@@ -0,0 +1,241 @@
+
+ * @copyright 2009 Jamie Kahgee
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: DBPage.php,v 1.1 2009/10/13 13:23:00 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ * @see References to other sections (if any)...
+ */
+
+
+/**
+ * Short description for class
+ *
+ * Long description (if any) ...
+ *
+ * @category Members
+ * @package Toolkit_Members
+ * @author Jamie Kahgee
+ To select more than one field, hold down the CTRL key
+ while selecting items.'
+ );
+ $e[] = array(
+ 'type' => 'advmultiselect',
+ 'req' => false,
+ 'name' => 'columns',
+ 'display' => 'Import Fields',
+ 'labels' => array('Fields', 'Available', 'Selected'),
+ 'opts' => $fields,
+ 'att' => array(
+ 'multiple' => 'multiple',
+ 'size' => 40,
+ 'style' => 'width: 200px;'
+ )
+ );
+ $e[] = array(
+ 'type' => 'group',
+ 'req' => false,
+ 'name' => 'control_buttons',
+ 'group' => $prevNext,
+ 'label' => '',
+ 'seperator' => ' ',
+ 'appendName' => false
+ );
+
+ $this->setupElements($e);
+ }
+
+ // }}}
+ // {{{ configureFilters()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return void
+ * @access protected
+ */
+ protected function configureFilters()
+ {
+ $f = array();
+
+ $f[] = array(
+ 'element' => '__ALL__',
+ 'filter' => 'trim',
+ );
+
+ $this->setupFilters($f);
+ }
+
+ // }}}
+ // {{{ _getCSVFields()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @return array Return description (if any) ...
+ * @access private
+ */
+ private function _getCSVFields()
+ {
+ $data =& $this->controller->container();
+
+ $row = 0;
+ $handle = fopen("./uploads/{$data['_upload']}", 'r');
+ $fields = fgetcsv($handle, 1000, ',');
+ fclose($handle);
+
+ $cleanFields = array();
+ foreach ($fields as $i) {
+ $j = $this->clean($i);
+ $cleanFields[$j] = $j;
+ }
+
+ return $cleanFields;
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/Import/FilePage.php b/Toolkit/Members/Import/FilePage.php
new file mode 100644
index 0000000..6121a1b
--- /dev/null
+++ b/Toolkit/Members/Import/FilePage.php
@@ -0,0 +1,173 @@
+
+ * @copyright 2009 Jamie Kahgee
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: FilePage.php,v 1.1 2009/10/13 13:23:00 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ * @see References to other sections (if any)...
+ */
+
+
+/**
+ * Short description for class
+ *
+ * Long description (if any) ...
+ *
+ * @category Members
+ * @package Toolkit_Members
+ * @author Jamie Kahgee
+ * // Define the rules for each element in the group.
+ * $num_rule = array(
+ * 'ERROR: Must contain a valid decimal number!',
+ * 'numeric'
+ * );
+ * // Collect together the rules for each element.
+ * $lat_rules = array('lat' => array($num_rule));
+ * $lon_rules = array('lon' => array($num_rule));
+ * $r[] = array(
+ * 'element' => 'latitude',
+ * 'message' => 'ERROR:',
+ * 'type' => 'group',
+ * 'format' => $lat_rules,
+ * 'validation' => $this->validationType,
+ * 'reset' => false,
+ * 'force' => false
+ * );
+ *
+ *
+ * To make a group required but not require every element in the group
+ * you can use the addGroupRule function again
+ * for example: say you have a group of checkboxes and you only only
+ * require 1 be checked. a simple group rule such as the following
+ * will handle this.
+ * N.B. notice the extra "howMany" index.
+ *
+ * $r[] = array(
+ * 'element' => 'element_name',
+ * 'message' => 'ERROR: Error to display!',
+ * 'type' => 'required',
+ * 'format' => null,
+ * 'howMany' => 1,
+ * 'validation'=> $this->validationType,
+ * 'reset' => true,
+ * 'force' => false,
+ * );
+ *
+ *
+ * @param array $rules Multi-Dimensional array of rules for form elements.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupRules(array $rules = null)
+ {
+ if (is_array($this->formElements)) {
+ foreach ($this->formElements as $e) {
+ if ($this->validationType == 'client') {
+ $label = $e['display'];
+ }
+ if ($e['req']) {
+ if ($e['type'] == 'group') {
+ foreach ($e['group'] as $ge) {
+ if ($ge['req']) {
+ $rule[$ge['name']][] = array(
+ 'ERROR: You must complete this field!',
+ 'required',
+ null,
+ $this->validationType
+ );
+ }
+ }
+ $this->addGroupRule($e['name'], $rule);
+ unset($rule);
+ } elseif ($e['type'] == 'date') {
+ if (!empty($e['error'])) {
+ // Custom error message for the date element.
+ $error = $e['error'];
+ } else {
+ // Default error message for the date element.
+ $error = 'ERROR: You must enter a date!';
+ }
+ $this->addGroupRule(
+ $e['name'],
+ $error,
+ 'required',
+ 3,
+ $this->validationType
+ );
+ if ($this->autoValidateDateElements) {
+ $this->addRule(
+ $e['name'],
+ 'ERROR: Date is invalid!',
+ 'callback',
+ array(&$this, 'checkDateInput')
+ );
+ }
+ } else {
+ $this->addRule(
+ $e['name'],
+ "$label ERROR: You must complete this field!",
+ 'required',
+ null,
+ $this->validationType
+ );
+ }
+ }
+ }
+ }
+ if (is_array($rules)) {
+ foreach ($rules as $r) {
+ if (!is_array($r['element'])) {
+ $group = ($this->getElementType($r['element']) == 'group');
+ }
+ if ($group) {
+ $this->addGroupRule(
+ $r['element'],
+ $r['message'],
+ $r['type'],
+ $r['format'],
+ $r['howMany'],
+ $r['validation'],
+ $r['reset']
+ );
+ }
+ }
+ }
+ }
+
+ // }}}
+ // {{{ setupFilters()
+
+ /**
+ * Sets any filters needed for the form elements when submitting
+ *
+ * @param array $filters Element filters.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupFilters($filters)
+ {
+ foreach ($filters as $f) {
+ $res = $this->applyFilter($f['element'], $f['filter']);
+
+ if (PEAR::isError($res)) {
+ Toolkit_Common::handleError($res);
+ }
+ }
+ }
+
+ // }}}
+ // {{{ setupDefaults()
+
+ /**
+ * Sets the form default values
+ *
+ * @param array $defaults Associative array of form default values.
+ *
+ * @return void
+ * @access protected
+ */
+ protected function setupDefaults($defaults)
+ {
+ $this->setDefaults($defaults);
+ }
+
+ // }}}
+ // {{{ clean()
+
+
+ /**
+ * Short description for function
+ *
+ * Long description (if any) ...
+ *
+ * @param unknown $node Parameter description (if any) ...
+ * @return unknown Return description (if any) ...
+ * @access protected
+ */
+ protected function clean($node)
+ {
+ $cleanNode = str_replace(' ', '_', $node);
+ return $cleanNode;
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/Import/ServerPage.php b/Toolkit/Members/Import/ServerPage.php
new file mode 100644
index 0000000..2e847e4
--- /dev/null
+++ b/Toolkit/Members/Import/ServerPage.php
@@ -0,0 +1,133 @@
+
+ * @copyright 2009 Jamie Kahgee
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @version CVS: $Id: ServerPage.php,v 1.1 2009/10/13 13:23:00 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ * @see References to other sections (if any)...
+ */
+
+
+/**
+ * Short description for class
+ *
+ * Long description (if any) ...
+ *
+ * @category Members
+ * @package Toolkit_Members
+ * @author Jamie Kahgee ';
+ if (is_array($this->interestsGroups)) {
+ foreach ($this->interestsGroups as $group => $gData) {
+ $renderer->setGroupTemplate('{element}
{content}', 'interest['.$group.']');
+ $renderer->setGroupElementTemplate('{element}', 'interest['.$group.']');
+ $renderer->setElementTemplate(' ', 'interest['.$group.']');
+ }
+ }
+ if (is_array($this->dGroups)) {
+ foreach ($this->dGroups as $group => $gData) {
+ $renderer->setGroupTemplate('{content}', 'discover['.$group.']');
+ $renderer->setGroupElementTemplate('{element}', 'discover['.$group.']');
+ $renderer->setElementTemplate(''.$required.'{label}'.$error.'{element} ', 'discover['.$group.']');
+ }
+ }
+ $renderer->setElementTemplate($tpl, 'submit');
+ }
+
+ // @codeCoverageIgnoreEnd
+ // }}}
+ // {{{ storeQuery()
+
+ /**
+ * Description for storeQuery()
+ *
+ * @return void
+ * @access public
+ * @throws PEAR_Error
+ */
+ function storeQuery()
+ {
+ $mid = $GLOBALS['memberAuth']->getAuthData('member_id');
+ try {
+ $query = serialize($_POST);
+ $sql = "
+ UPDATE member_leads
+ SET query = :query
+ WHERE member_id = :mid";
+ $stmt2 = $this->dbh->prepare($sql);
+ $stmt2->bindParam(":mid", $mid, PDO::PARAM_INT);
+ $stmt2->bindParam(":query", $query, PDO::PARAM_STR);
+ $stmt2->execute();
+ } catch (PDOException $e) {
+ Toolkit_Common::handleError($e);
+ }
+ }// }}}
+ // {{{ toHtml()
+
+ /**
+ * Call the rendering function to get the form in a string
+ *
+ * @param PDO $dbh PDO
+ *
+ * @access public
+ * @return string $file The Form to be rendered or success msg.
+ */
+ public function toHtml(PDO $dbh)
+ {
+ $this->setupRenderers();
+ $GLOBALS['styleSheets'][] = MEDIA_APP_BASE_URL . 'libjs/Jscal/system.css';
+ $GLOBALS['bottomScripts'][] = MEDIA_APP_BASE_URL . 'libjs/Jscal/utils.js';
+ $GLOBALS['bottomScripts'][] = MEDIA_APP_BASE_URL . 'libjs/Jscal/calendar.js';
+ $GLOBALS['bottomScripts'][] = MEDIA_APP_BASE_URL . 'libjs/Jscal/calendar-en.js';
+ $GLOBALS['bottomScripts'][] = MEDIA_APP_BASE_URL . 'libjs/Jscal/calendar-setup.js';
+ $GLOBALS['bottomScripts'][] = MEDIA_BASE_URL . 'Toolkit/Members/Leads/libjs/visitorLeads.js';
+
+ if ($this->validate()) {
+ $export = new Toolkit_Members_Leads_ExportLeads($dbh);
+ $export->setQuery();
+ $this->storeQuery();
+ $export->setDefaultSort(array('sort_field' => 'ASC'));
+ $file = $export->exportAsFile($dbh);
+ if ($file) {
+ return $file;
+ } else {
+ return ''.$required.'{label}'.$error.'{element} ';
+ $('#sdate3').after(img);
+ //$("#startcal").css('display', 'inline');
+ },
+
+ setupEDateCalendar: function()
+ {
+ var img = '
';
+ $('#edate3').after(img);
+ //$("#endcal").css('display', 'inline');
+ }
+
+};
+
+$(document).ready(Event.init);
diff --git a/Toolkit/Members/Map.php b/Toolkit/Members/Map.php
new file mode 100644
index 0000000..a2c92d5
--- /dev/null
+++ b/Toolkit/Members/Map.php
@@ -0,0 +1,100 @@
+
+ * @copyright 2009 Gaslight Media
+ * @license Gaslight Media
+ * @version CVS: $Id$
+ * @link <>
+ */
+
+/**
+ * Short description for class
+ *
+ * Long description (if any) ...
+ *
+ * @category Toolkit
+ * @package Toolkit_Members
+ * @author Jamie Kahgee
'.print_r($classData, true).'
';
+ //exit;
+ $sql = Toolkit_Common::createSQLInsert(
+ 'category',
+ array_keys($classData)
+ );
+ $sql .= " RETURNING category_id";
+ $stmt = Toolkit_Common::prepareQuery(
+ $dbh,
+ 'category',
+ $sql,
+ $classData
+ );
+ $stmt->execute();
+ $this->setCategoryId($stmt->fetchColumn());
+ }
+ /**
+ * given a category name return id create category if needed
+ *
+ * @param PDO $dbh Database connection
+ * @param String $name Category Name
+ *
+ * @return Object
+ */
+ function fetchByName(PDO $dbh, $name)
+ {
+ $sql = "
+ SELECT " . implode(',', $this->getClassVars())."
+ FROM category
+ WHERE name = :name";
+ $stmt = $dbh->prepare($sql);
+ $stmt->bindParam(":name", $name, PDO::PARAM_STR);
+ $stmt->execute();
+ $row = $stmt->fetch(PDO::FETCH_ASSOC);
+ if ($row) {
+ $category = new Toolkit_Members_MemberImport_Category();
+ $category->setCategoryId($row['category_id']);
+ $category->setName($row['name']);
+ $category->setParent_id($row['parent_id']);
+ return $category;
+ } else {
+ return false;
+ }
+ }
+ /**
+ * get all clas properties as an array (just names)
+ *
+ * @return Array
+ */
+ public function getClassVars()
+ {
+ return array_keys(get_class_vars(get_class($this)));
+ }
+ /**
+ * set category id
+ *
+ * @param Int $id Category id
+ *
+ * @return void
+ */
+ public function setCategoryId($id)
+ {
+ if (!$this->category_id) {
+ $this->category_id = $id;
+ }
+ }
+ /**
+ * Checks the id of the object if it is set then calls update othervise
+ * calls insert function
+ *
+ * @param PDO $dbh Database connection
+ *
+ * @return viod
+ */
+ public function save(PDO $dbh)
+ {
+ if ($this->category_id) {
+ $this->_update($dbh);
+ } else {
+ $this->_insert($dbh);
+ }
+ }
+ /**
+ * Validates the property
+ *
+ * @param String $name property name
+ *
+ * @return String
+ */
+ protected function validateAttribute($name)
+ {
+ if (property_exists(get_class($this), $name)) {
+ return strtolower($name);
+ }
+ }
+}
diff --git a/Toolkit/Members/MemberImport/City.php b/Toolkit/Members/MemberImport/City.php
new file mode 100644
index 0000000..d48d8b2
--- /dev/null
+++ b/Toolkit/Members/MemberImport/City.php
@@ -0,0 +1,135 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_MemberImport_City
+ *
+ * member city table class
+ *
+ * @category Toolkit
+ * @package Members
+ * @author Steve Sutton '.print_r($this->members, true).'
';
+ return true;
+ }
+
+ /**
+ * 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.
+ *
+ * @return string form HTML state
+ * @access public
+ */
+ public function toHtml()
+ {
+ if ($this->validate()) {
+ $this->cleanForm();
+
+ if ($this->process(array(&$this, 'processForm'), $this->mergeFiles)) {
+ $this->freeze();
+ $output = $this->successMsg;
+ }
+ } elseif ($this->isSubmitted()) {
+ $output = $this->errorMsg;
+ $output .= parent::toHTML();
+ } else {
+ $output = parent::toHTML();
+ }
+ return $output;
+ }
+}
diff --git a/Toolkit/Members/MemberImport/Member.php b/Toolkit/Members/MemberImport/Member.php
new file mode 100644
index 0000000..54d4516
--- /dev/null
+++ b/Toolkit/Members/MemberImport/Member.php
@@ -0,0 +1,667 @@
+
+ * @license Gaslight Media
+ * @link <>
+ */
+/**
+ * Toolkit_Members_MemberImport_Member
+ *
+ * Member class for importing member
+ *
+ * @category Toolkit_Members
+ * @package Members
+ * @author Jamie Kahgee
';
+ }
+ echo $form->toHtml();
+}
+if (isset($_REQUEST['_qf__import-file'])
+ || isset($_REQUEST['_qf__import-members'])
+ || $_GET['skip'] == 't'
+) {
+ // next page
+ $form2 = new Toolkit_Members_MemberImport_ImportForm(
+ 'import-members',
+ 'post',
+ 'index.php',
+ null,
+ null,
+ true
+ );
+ $form2->configureForm();
+ echo $form2->toHtml();
+}
diff --git a/Toolkit/Members/MembersOnly/BreadCrumbs.php b/Toolkit/Members/MembersOnly/BreadCrumbs.php
new file mode 100644
index 0000000..b06c37c
--- /dev/null
+++ b/Toolkit/Members/MembersOnly/BreadCrumbs.php
@@ -0,0 +1,65 @@
+
+ * @copyright 2012 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: $id$
+ * @link <>
+ *
+ */
+
+/**
+ * Toolkit_Members_MembersOnly_BreadCrumbs
+ *
+ * Description of Toolkit_Members_MembersOnly_BreadCrumbs
+ *
+ * @category Toolkit
+ * @package Members_MembersOnly
+ * @author Jamie Kahgee ';
+ $html .= '
';
+ }
+
+ $this->_createPage($html);
+ }
+
+ // }}}
+ // {{{ addEventAction()
+ /**
+ * Description of addEventAction()
+ *
+ * @return void
+ * @access public
+ */
+ public function addEventAction()
+ {
+ // get code for edit event here
+ // application configuration
+ $conf = new Config;
+ $root =& $conf->parseConfig(
+ BASE . 'Toolkit/Members/config.ini',
+ 'IniFile'
+ );
+ $eventMapper = new EventMapper(Toolkit_Database::getInstance());
+ $form = new Toolkit_Members_Events_CommonEditEvent(
+ $this->registry->dbh,
+ 'edit_event',
+ $method = 'post',
+ '',
+ '',
+ null,
+ false,
+ $eventMapper
+ );
+
+ $form->configureForm();
+ $html = $form->toHtml(
+ Toolkit_Database::getInstance(),
+ new Toolkit_Image_Server()
+ );
+
+ $this->_createPage($html);
+ }
+
+ // }}}
+}
diff --git a/Toolkit/Members/MembersOnly/Controller.php b/Toolkit/Members/MembersOnly/Controller.php
new file mode 100644
index 0000000..3f06b0e
--- /dev/null
+++ b/Toolkit/Members/MembersOnly/Controller.php
@@ -0,0 +1,290 @@
+
+ * @copyright 2012 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: $id$
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_MembersOnly_Controller
+ *
+ * Description of Toolkit_Members_MembersOnly_Controller
+ *
+ * @category Toolkit
+ * @package Members_MembersOnly
+ * @author Jamie Kahgee
+ ';
+ foreach( $data as $row ){
+ $html .= '
+ Event
+ Status
+ Start
+ End
+
+ ';
+ }
+ $html .= '
+
+
+
+ '.$row->getHeader().'
+
+
+ '.( ( $row->getActive() == 't' ) ? 'Active' : 'Pending').'
+
+
+ '.$row->getStarting().'
+
+
+ '.$row->getEnding().'
+
+ Exposure Reports
\n";
+ $out .= "\n";
+ $out .= "\t
\n";
+ $out .= "
\n";
+ }
+
+ return $out;
+ }
+
+ // }}}
+
+ // {{{ _pageToolbox()
+
+ /**
+ * Description of _pageToolbox
+ *
+ * @return string
+ * @throws RuntimeException
+ * @access private
+ */
+ private function _pageToolbox()
+ {
+ if (!ctype_digit($_GET['page_id'])) {
+ throw new RuntimeException(
+ '$_GET[\'page_id\'] must be an integer'
+ );
+ }
+
+ $toolbox = new GLM_TEMPLATE($_GET['page_id']);
+ $out = $toolbox->get_category();
+ $out .= $toolbox->get_listings();
+
+ return $out;
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/MembersOnly/CouponsController.php b/Toolkit/Members/MembersOnly/CouponsController.php
new file mode 100644
index 0000000..2bf4094
--- /dev/null
+++ b/Toolkit/Members/MembersOnly/CouponsController.php
@@ -0,0 +1,216 @@
+
+ * @copyright 2012 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: $id$
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_MembersOnly_IndexController
+ *
+ * Description of Toolkit_Members_MembersOnly_IndexController
+ *
+ * @category Toolkit
+ * @package Members_MembersOnly
+ * @author Jamie Kahgee \n";
+ $html .= "
\n";
+ }
+ } catch (PDOException $e) {
+ Toolkit_Logger::logException('DB Error', $e);
+ throw new Toolkit_Members_Exception(
+ 'Error fetching member coupons list'
+ );
+ }
+
+ $this->_createPage($html);
+ }
+
+ // }}}
+ // {{{ addCouponAction()
+
+ /**
+ * Description of addCouponAction()
+ *
+ * @return void
+ * @access public
+ */
+ public function addCouponAction()
+ {
+ // application configuration
+ $conf = new Config;
+ $root =& $conf->parseConfig(
+ BASE . 'Toolkit/Members/config.ini',
+ 'IniFile'
+ );
+
+ $couponMailerTemplateData = new stdClass();
+ $couponMailerTemplateData->memberName = $this->registry->memberName;
+
+ $flexyOptions = $this->registry->flexyOptions;
+ $flexyOptions['templateDir'] = BASE . 'Toolkit/Members/templates';
+ $flexyOptions['compileDir'] = BASE . 'Toolkit/Members/templates/compiled';
+ $tEngine = new HTML_Template_Flexy($flexyOptions);
+ $tEngine->compile('editCouponEmail.tpl');
+ $mailer = new Toolkit_Members_Coupons_Mailer(
+ $tEngine,
+ new Mail_mime("\n"),
+ Mail::factory('mail')
+ );
+
+ $form = new Toolkit_Members_Coupons_EditCouponForm(
+ 'edit_coupon'
+ );
+
+ $form->configureForm($this->registry->dbh, $root);
+ $html = $form->toHtml(
+ Toolkit_Database::getInstance(),
+ new Toolkit_Image_Server(),
+ new Toolkit_Coupons_MemberCouponFactory(),
+ $mailer,
+ $couponMailerTemplateData
+ );
+
+ $this->_createPage($html);
+ }
+
+ // }}}
+}
diff --git a/Toolkit/Members/MembersOnly/EditProfileController.php b/Toolkit/Members/MembersOnly/EditProfileController.php
new file mode 100644
index 0000000..96fe87c
--- /dev/null
+++ b/Toolkit/Members/MembersOnly/EditProfileController.php
@@ -0,0 +1,86 @@
+
+ * @copyright 2012 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: $id$
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_MembersOnly_EditProfileController
+ *
+ * Description of Toolkit_Members_MembersOnly_EditProfileController
+ *
+ * @category Toolkit
+ * @package Members_MembersOnly
+ * @author Jamie Kahgee \n";
+ $html .= "\t \n";
+ foreach ($data as $row) {
+ $link = sprintf(
+ $format,
+ MEDIA_BASE_URL . "members-only-area/?rt=Coupons&ac=addCoupon&page_id={$_REQUEST['page_id']}&id={$row['id']}"
+ );
+ if ($row['pending']) {
+ $status = 'Pending';
+ } elseif ($row['active']) {
+ $status = 'Active';
+ } else {
+ $status = 'Disabled';
+ }
+ $html .= " \n";
+ $html .= "\tCoupons \n";
+ $html .= "\tStatus \n";
+ $html .= "\tStart \n";
+ $html .= "\tEnd \n";
+ $html .= "\tExpire \n";
+ $html .= "\n";
+ $html .= "\t \n";
+ }
+ $html .= "$link \n";
+ $html .= "\t{$row['title']} \n";
+ $html .= "\t$status \n";
+ $html .= "\t{$row['sdate']} \n";
+ $html .= "\t{$row['edate']} \n";
+ $html .= "\t{$row['expiration']} \n";
+ $html .= "';
+ $html .= '
';
+ }
+ } catch (PDOException $e) {
+ Toolkit_Logger::logException('DB Error', $e);
+ throw new Toolkit_Members_Exception(
+ 'Error fetching member Events list'
+ );
+ }
+ $this->_createPage($html);
+ }
+
+ // }}}
+ // {{{ addEventAction()
+ /**
+ * Description of addEventAction()
+ *
+ * @return void
+ * @access public
+ */
+ public function addEventAction()
+ {
+ // get code for edit event here
+ // application configuration
+ $conf = new Config;
+ $root =& $conf->parseConfig(
+ BASE . 'Toolkit/Members/config.ini',
+ 'IniFile'
+ );
+ $form = new Toolkit_Members_Events_EditEvent(
+ $this->registry->dbh,
+ 'edit_event'
+ );
+
+ $form->configureForm();
+ $html = $form->toHtml(
+ Toolkit_Database::getInstance(),
+ new Toolkit_Image_Server()
+ );
+
+ $this->_createPage($html);
+ }
+
+ // }}}
+}
diff --git a/Toolkit/Members/MembersOnly/IndexController.php b/Toolkit/Members/MembersOnly/IndexController.php
new file mode 100644
index 0000000..c67095c
--- /dev/null
+++ b/Toolkit/Members/MembersOnly/IndexController.php
@@ -0,0 +1,76 @@
+
+ * @copyright 2012 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: $id$
+ * @link <>
+ */
+
+/**
+ * Toolkit_Members_MembersOnly_IndexController
+ *
+ * Description of Toolkit_Members_MembersOnly_IndexController
+ *
+ * @category Toolkit
+ * @package Members_MembersOnly
+ * @author Jamie Kahgee
+ ';
+ foreach( $data as $row ){
+ $html .= '
+ Event
+ Status
+ Start
+ End
+
+ ';
+ }
+ $html .= '
+
+
+
+ '.$row["header"].'
+
+
+ '.( ( $row['visable'] == 't' ) ? 'Active' : 'Pending').'
+
+
+ '.$row["bdate"].'
+
+
+ '.$row["edate"].'
+
+ Exposure Reports
\n";
+ $out .= "\n";
+ $out .= "\t
\n";
+ $out .= "
\n";
+ }
+
+ $dReport = new Toolkit_Members_ExposureDetailReports(
+ $this->registry->dbh
+ );
+ $dReport->setQuery($this->registry->memberId);
+ $dReport->setDefaultSort(array('month' => 'desc'));
+
+ $rEngine = new Structures_DataGrid_Renderer_Flexy();
+ $tplOpts = Toolkit_Members::getFlexyOptions();
+ $tReportsEngine = new HTML_Template_Flexy($tplOpts);
+ $rEngine->setContainer($tReportsEngine);
+
+ $out .= $dReport->toHtml($rEngine);
+
+ $glmPage->toolboxContent .= $out;
+
+ $glmPage->topScripts = Toolkit_Common::getScripts($GLOBALS['topScripts']);
+ $glmPage->bottomScripts = Toolkit_Common::getScripts($GLOBALS['bottomScripts']);
+ $glmPage->styles = Toolkit_Common::getStyleSheets();
+
+ $tEngine->compile('template.html');
+ $tEngine->outputObject($glmPage);
+ }
+
+ // }}}
+}
diff --git a/Toolkit/Members/MembersOnly/index.php b/Toolkit/Members/MembersOnly/index.php
new file mode 100644
index 0000000..b150e2e
--- /dev/null
+++ b/Toolkit/Members/MembersOnly/index.php
@@ -0,0 +1,91 @@
+
+ * @copyright 2012 Gaslight Media
+ * @license Gaslight Media
+ * @version SVN: $id$
+ * @link <>
+ */
+require_once '../../../setup.phtml';
+HTTP_Session2::useCookies(false);
+HTTP_Session2::start();
+// application configuration
+$conf = new Config;
+$root =& $conf->parseConfig(BASE . 'Toolkit/Members/config.ini', 'IniFile');
+
+$authContainer = new Toolkit_Members_AuthContainer(
+ Toolkit_Database::getInstance(),
+ array(
+ 'table' => 'member',
+ 'usernamecol' => 'member_login',
+ 'passwordcol' => 'member_passwd',
+ 'db_fields' => array('member_id', 'member_name'),
+ 'cryptType' => 'none',
+ 'db_where' => 'new_member <> true AND active = true',
+ )
+);
+
+$memberAuth = new Toolkit_Members_Auth(
+ $root,
+ $authContainer,
+ '',
+ false
+);
+$memberAuth->setIdle();
+$memberAuth->start();
+
+if (isset($_GET['logout'])) {
+ $memberAuth->logout();
+}
+
+if (!$memberAuth->checkAuth()) {
+ // Manually adjust the authentication status for empty credentials
+ if (empty($_POST['username']) || empty($_POST['password'])) {
+ $status = -3;
+ }
+ $status = $memberAuth->getStatus();
+ header('Location: ' . MEDIA_BASE_URL . 'index.php?catid=' . MEMBERS_CATEGORY . '&status=' . $status);
+} else {
+ if (!Toolkit_Membersonly::checkMemberExists(
+ Toolkit_Database::getInstance(),
+ $memberAuth->getAuthData('member_id')
+ )) {
+ $memberAuth->logout();
+ $status = $memberAuth->getStatus();
+ header('Location: ' . MEDIA_BASE_URL . 'index.php?catid=' . MEMBERS_CATEGORY . '&status=' . $status);
+ }
+ // Carry over from old code
+ // @todo: work to remove
+ $pageId = filter_var($_REQUEST['page_id']);
+ if ($pageId) {
+ $_GET['catid'] = $pageId;
+ $_GET['page_id'] = $pageId;
+ }
+ $_GET['catid'] = ctype_digit($_REQUEST['page_id'])
+ ? $_REQUEST['page_id']
+ : MEMBERS_ONLY_HOME_PAGE;
+
+ // Create a new registry so we don't pollute the global namespace
+ $registry = new Toolkit_Registry;
+
+ $registry->cacheOptions = $GLOBALS['cacheOptions'];
+ $registry->flexyOptions = $GLOBALS['flexyOptions'];
+ $registry->memberId = $memberAuth->getAuthData('member_id');
+ $registry->memberName = $memberAuth->getAuthData('member_name');
+ $registry->logger = Toolkit_Logger::getLogger();
+ $registry->pageid = $_GET['catid'];
+ $registry->dbh = Toolkit_Database::getInstance();
+
+ // Create a router so we can get where we need to be.
+ $registry->router = new Toolkit_Router($registry);
+ $registry->router->setPath(BASE . 'Toolkit/Members/MembersOnly');
+ $registry->router->setApplication('Members/MembersOnly');
+
+ $registry->router->loader();
+}
diff --git a/Toolkit/Members/PackageList.php b/Toolkit/Members/PackageList.php
new file mode 100644
index 0000000..1870d19
--- /dev/null
+++ b/Toolkit/Members/PackageList.php
@@ -0,0 +1,315 @@
+
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release CVS: $Id: SearchList.php,v 1.47 2010/07/14 23:31:14 jamie Exp $
+ * @link http://demo.gaslightmedia.com
+ */
+
+/**
+ * Datagrid of search results of member db
+ *
+ * @category MembersDB
+ * @package Toolkit_Members
+ * @author Jamie Kahgee ', '
');
+
+ $menu->render($renderer);
+ return $renderer->toHtml();
+ }
+
+ // }}}
+
+ // {{{ setupAdminNavStructure()
+
+ /**
+ * Sets up a multi dimensional array used for the subnav structure
+ *
+ * @return mixed false on sql error. otherwise void
+ * @access public
+ */
+ public function setupAdminNavStructure()
+ {
+ $singularType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'singular')
+ ->getContent();
+ $pluralType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'plural')
+ ->getContent();
+
+ // Default URI parameters that will get us back to the
+ // page were we can edit member data.
+ $params = "rt=Members&ac=editMember";
+
+ // If we are editing an existing member, then we need to
+ // add their id into the URI so we know who we are editing
+ if (is_numeric($_GET['id'])) {
+ $params .= "&id={$_GET['id']}";
+ }
+
+ // We always show the member info tab.
+ // whether we are adding a member or editing a member
+ $nav = array(
+ 'info' => array(
+ 'title' => "$singularType Info",
+ 'url' => "/members.php?$params",
+ 'desc' => "View and edit $singularType in the database",
+ )
+ );
+ if (is_numeric($_GET['id'])) {
+ $nav['photos'] = array(
+ 'title' => 'Photos',
+ 'url' => "/members.php?$params",
+ 'desc' => "View and edit $pluralType in the database",
+ );
+ $nav['packages'] = array(
+ 'title' => 'Packages',
+ 'url' => "/members.php?$params",
+ 'desc' => "View and edit $singularType categories",
+ );
+ $nav['amenities'] = array(
+ 'title' => 'Amenities',
+ 'url' => "/members.php?$params",
+ 'desc' => "View and edit $singularType amenities",
+ );
+ $nav['files'] = array(
+ 'title' => 'Files',
+ 'url' => "/members.php?$params",
+ 'desc' => "View and edit $singularType regions",
+ );
+ $nav['contacts'] = array(
+ 'title' => 'Contacts',
+ 'url' => "/members.php?$params",
+ 'desc' => "View and edit $singularType cities",
+ );
+ $billingModule = $this->config->getItem('section', 'admin')
+ ->getItem('directive', 'billing')
+ ->getContent();
+
+
+ if ($billingModule) {
+ $billingNav = new Toolkit_Members_Billing_RecordNavigation();
+ $nav = $billingNav->getNavigationArray($params, $nav);
+ }
+ }
+
+ $hasPhotos = $this->config
+ ->getItem('section', 'admin')
+ ->getItem('directive', 'photos')
+ ->getContent();
+
+ if (!$hasPhotos) {
+ unset($nav['photos']);
+ }
+
+ $hasPackages = $this->config
+ ->getItem('section', 'admin')
+ ->getItem('directive', 'packages')
+ ->getContent();
+
+ if (!$hasPackages) {
+ unset($nav['packages']);
+ }
+
+ $hasAmenities = $this->config
+ ->getItem('section', 'admin')
+ ->getItem('directive', 'amenities')
+ ->getContent();
+
+ if (!$hasAmenities) {
+ unset($nav['amenities']);
+ }
+
+ $hasFiles = $this->config
+ ->getItem('section', 'admin')
+ ->getItem('directive', 'files')
+ ->getContent();
+
+ if (!$hasFiles) {
+ unset($nav['files']);
+ }
+
+ $hasContacts = $this->config
+ ->getItem('section', 'admin')
+ ->getItem('directive', 'contacts')
+ ->getContent();
+
+ if (!$hasContacts) {
+ unset($nav['contacts']);
+ }
+
+ // make full URI's and attach which tab we are working with
+ foreach ($nav as $i => &$j) {
+ $j['url'] = MEDIA_BASE_URL . 'admin' . $j['url'] . "&tab=$i";
+ }
+
+ $this->navStructure = $nav;
+ }
+
+ // }}}
+ // {{{ setupUserNavSructure()
+
+ /**
+ * Sets up a multi dimensional array used for the subnav structure
+ *
+ * @return mixed false on sql error. otherwise void
+ * @access public
+ */
+ public function setupUserNavStructure()
+ {
+ $singularType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'singular')
+ ->getContent();
+ $pluralType = $this->config
+ ->getItem('section', 'listing type')
+ ->getItem('directive', 'plural')
+ ->getContent();
+
+ $params = "rt=EditProfile";
+ $nav = array(
+ 'info' => array(
+ 'title' => "$singularType Info",
+ 'url' => "/?$params",
+ 'desc' => "View and edit $singularType in the database",
+ ),
+ 'photos' => array(
+ 'title' => 'Photos',
+ 'url' => "/?$params",
+ 'desc' => "View and edit $pluralType in the database",
+ ),
+ 'packages' => array(
+ 'title' => 'Packages',
+ 'url' => "/?$params",
+ 'desc' => "View and edit $singularType categories",
+ ),
+ 'amenities' => array(
+ 'title' => 'Amenities',
+ 'url' => "/?$params",
+ 'desc' => "View and edit $singularType amenities",
+ ),
+ 'files' => array(
+ 'title' => 'Files',
+ 'url' => "/?$params",
+ 'desc' => "View and edit $singularType regions",
+ ),
+ 'contacts' => array(
+ 'title' => 'Contacts',
+ 'url' => "/?$params",
+ 'desc' => "View and edit $singularType cities",
+ ),
+ );
+
+ $hasPhotos = $this->config
+ ->getItem('section', 'members only')
+ ->getItem('directive', 'photos')
+ ->getContent();
+
+ if (!$hasPhotos) {
+ unset($nav['photos']);
+ }
+
+ $hasPackages = $this->config
+ ->getItem('section', 'members only')
+ ->getItem('directive', 'packages')
+ ->getContent();
+
+ if (!$hasPackages) {
+ unset($nav['packages']);
+ }
+
+ $hasAmenities = $this->config
+ ->getItem('section', 'members only')
+ ->getItem('directive', 'amenities')
+ ->getContent();
+
+ if (!$hasAmenities) {
+ unset($nav['amenities']);
+ }
+
+ $hasFiles = $this->config
+ ->getItem('section', 'members only')
+ ->getItem('directive', 'files')
+ ->getContent();
+
+ if (!$hasFiles) {
+ unset($nav['files']);
+ }
+
+ $hasContacts = $this->config
+ ->getItem('section', 'members only')
+ ->getItem('directive', 'contacts')
+ ->getContent();
+
+ if (!$hasContacts) {
+ unset($nav['contacts']);
+ }
+
+ // make full URI's and attach which tab we are working with
+ foreach ($nav as $i => &$j) {
+ $j['url'] = MEDIA_BASE_URL . 'members-only-area' . $j['url'] . "&tab=$i";
+ }
+
+ $this->navStructure = $nav;
+ }
+
+ // }}}
+}
+?>
diff --git a/Toolkit/Members/Rules/DuplicateMember.php b/Toolkit/Members/Rules/DuplicateMember.php
new file mode 100644
index 0000000..ba030ee
--- /dev/null
+++ b/Toolkit/Members/Rules/DuplicateMember.php
@@ -0,0 +1,99 @@
+
+ * @copyright 2010 Jamie Kahgee
+ * @license http://www.gaslightmedia.com/ Gaslightmedia
+ * @version CVS: $Id: DuplicateMember.php,v 1.2 2010/05/15 15:14:54 jamie Exp $
+ * @link <>
+ * @see References to other sections (if any)...
+ */
+
+
+/**
+ * Validate if a member name is being duplicated or not
+ *
+ * Check to see if the member name exists already in the database.
+ * If it does not, then it is a valid name. Else it is invalid.
+ *
+ * @category Members
+ * @package Toolkit_Members
+ * @author Jamie Kahgee ', 'submit');
+ }
+
+ // }}}
+
+ // {{{ processData()
+
+ /**
+ * Processes the data submitted by the form
+ *
+ * Gets the login credentials for the matching email address and mails
+ * them to that email address
+ *
+ * @param array $values submitted form values
+ *
+ * @return boolean Result of mail
+ * @access protected
+ */
+ protected function processData($values)
+ {
+ try {
+ $sql = "
+ SELECT email, verify_password as password
+ FROM {$this->tableName}
+ WHERE email = :email";
+
+ $stmt = $this->dbh->prepare($sql);
+ $stmt->bindParam(':email', $values['email'], PDO::PARAM_STR);
+ $stmt->execute();
+ $row = $stmt->fetch();
+
+ $htmlMsg
+ = "Here is your " . SITENAME . " password:{element}
" .
+ "Email: {$values['email']}
" .
+ "Password: {$row['password']}
";
+
+ $msg
+ = "Here is your " . SITENAME . " password:\n\n" .
+ "Email: {$values['email']}\n" .
+ "Password: {$row['password']}";
+
+ $crlf = "\n";
+ $mimeMail = new Mail_mime($crlf);
+ $mimeMail->setFrom(SITENAME . ' <' . OWNER_EMAIL . '>');
+ $mimeMail->setSubject('Your ' . SITENAME . ' Password');
+ $mimeMail->setHTMLBody($htmlMsg);
+ $mimeMail->setTXTBody($msg);
+
+ $mail =& Mail::factory('mail');
+ $body = $mimeMail->get();
+ $headers = $mimeMail->headers($hdrs);
+
+ $res = $mail->send($values['email'], $headers, $body);
+
+ return PEAR::isError($res) ?
+ Toolkit_Common::handleError($res) :
+ $res;
+ } catch (PDOException $e) {
+ Toolkit_Common::handlError($e);
+ }
+ }
+
+ // }}}
+
+ // {{{ toHtml()
+
+ /**
+ * Returns an HTML version of the form
+ *
+ * @return string HTML version of the form
+ * @access public
+ */
+ public function toHtml()
+ {
+ $this->setupRenderers();
+ if ($this->validate()) {
+ if ($this->process(array(&$this, 'processData'))) {
+ $url = MEDIA_BASE_URL . 'index.php?catid=' . MEMBER_SESSION_PAGE;
+ $e =& $this->getElement('email');
+ $email = $e->getValue();
+ $output
+ = "