Example #1
1
 function handle(&$params)
 {
     if (!@$_REQUEST['email']) {
         return PEAR::raiseError("No email address  specified");
     }
     import('HTML/QuickForm.php');
     $form = new HTML_QuickForm('opt_out_form', 'post');
     $form->addElement('hidden', 'email', $_REQUEST['email']);
     $form->addElement('hidden', '-action', 'email_opt_out');
     $form->addElement('submit', 'submit', 'Cancel Subscription');
     if ($form->validate()) {
         $res = mysql_query("replace into dataface__email_blacklist (email) values ('" . addslashes($_REQUEST['email']) . "')", df_db());
         if (!$res) {
             trigger_error(mysql_error(df_db()), E_USER_ERROR);
         }
         header('Location: ' . DATAFACE_SITE_HREF . '?--msg=' . urlencode('You have successfully opted out of our mail list.  You will no longer receive emails from us.'));
         exit;
     }
     ob_start();
     $form->display();
     $html = ob_get_contents();
     ob_end_clean();
     $context = array();
     $context['form'] = $html;
     df_register_skin('email', DATAFACE_PATH . '/modules/Email/templates');
     df_display($context, 'email/opt_out_form.html');
 }
Example #2
0
 function handle($params)
 {
     $js = Dataface_JavascriptTool::getInstance();
     $js->import('tests/doctest.js');
     $js->setMinify(false);
     $js->setUseCache(false);
     df_register_skin('xatajax', XATAJAX_PATH . DIRECTORY_SEPARATOR . 'templates');
     df_display(array(), 'tests/doctest.html');
 }
Example #3
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     $res = mysql_query("select gridID,gridName from dataface__DataGrids where tableName='" . addslashes($query['-table']) . "'", df_db());
     $grids = array();
     while ($row = mysql_fetch_assoc($res)) {
         $grids[$row['gridID']] = array('name' => $row['gridName'], 'url' => $app->url('-gridid=' . $row['gridID'] . '&-action=DataGrid_view'));
     }
     //print_r($grids);
     df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
     df_display(array('grids' => $grids), 'DataGrid/list.html');
 }
 function handle($params)
 {
     $js = Dataface_JavascriptTool::getInstance();
     $js->import('xatacard/layout/tests/RecordSetTest.js');
     $js->setMinify(false);
     $js->setUseCache(false);
     df_register_skin('xatajax', XATAJAX_PATH . DIRECTORY_SEPARATOR . 'templates');
     try {
         df_display(array(), 'tests/xatacard/layout/RecordSet/RecordSetTest.html');
     } catch (Exception $ex) {
         //echo "here";exit;
         while ($ex) {
             echo '<h3>' . $ex->getMessage() . '</h3>';
             echo nl2br(df_escape($ex->getTraceAsString()));
             $ex = $ex->getPrevious();
         }
     }
 }
Example #5
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     // We need to load the current data grid from the database.
     // Its id is provided in the -gridid request parameter.
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     if (!@$query['-gridid']) {
         // No grid was specified.. so we will just take the first grid
         $grids = $mod->getDataGrids();
         if (!$grids) {
             // No grids were found.  We need to create one
             $table =& Dataface_Table::loadTable($query['-table']);
             $grid = $mod->createDataGrid($query['-table'] . ' default grid', $query['-table'], array_keys($table->fields()));
             $res = $mod->saveDataGrid($grid);
             if (PEAR::isError($res)) {
                 return $res;
             }
             $dataGrid =& $grid;
         } else {
             $dataGrid = $grids[0];
         }
     }
     if (PEAR::isError($dataGrid)) {
         return $dataGrid;
     }
     if (!@$dataGrid) {
         $dataGrid =& $mod->getDataGrid($query['-gridid']);
     }
     if (!$dataGrid) {
         return PEAR::raiseError("Error, the specified data grid could not be found");
     }
     $json = new Services_JSON();
     $jsonFieldDefs = $json->encode($dataGrid->getFieldDefs(true));
     df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
     df_display(array('grid' => &$dataGrid, 'fieldDefs' => $jsonFieldDefs, 'json' => &$json), 'DataGrid/view.html');
 }
Example #6
0
 function handle($params)
 {
     $app = Dataface_Application::getInstance();
     $conf =& $app->_conf;
     $js = Dataface_JavascriptTool::getInstance();
     $js->setMinify(false);
     $js->setUseCache(false);
     if (isset($conf['_xatadoc'])) {
         foreach ($conf['_xatadoc_path'] as $f => $enabled) {
             if ($enabled) {
                 $js->addPath($f);
             }
         }
     }
     //print_r($this->getPaths());exit;
     foreach ($this->getPaths() as $p) {
         $this->crawlPath($p);
     }
     $js->import('actions/xatadoc.js');
     df_register_skin('xatajax', XATAJAX_PATH . DIRECTORY_SEPARATOR . 'templates');
     df_display(array(), 'xatadoc.html');
 }
Example #7
0
 public function registerSkin()
 {
     $s = DIRECTORY_SEPARATOR;
     df_register_skin('g2', dirname(__FILE__) . $s . 'templates');
 }
Example #8
0
 /**
  * implements action handle() method.
  */
 function handle(&$params)
 {
     $action =& $params['action'];
     //print_r($params);
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $query['-skip'] = 0;
     $query['-limit'] = 9999999;
     // Let's validate some of the parameters first
     // The actions.ini file should define an email_column and email_table parameters
     // to indicate:
     //	a. the name of the column from the current table that should be used
     //	    as the "send to" email address.
     //	b. the name of the table that should store the email messages.
     if (!@$action['email_column']) {
         return PEAR::raiseError("No email column specified in actions.ini", DATAFACE_E_WARNING);
     }
     if (!@$action['email_table']) {
         return PEAR::raiseError("No email table specified in actions.ini", DATAFACE_E_WARNING);
     }
     // Make sure the table and column names are not malicious.
     $this->emailColumn = $col = $action['email_column'];
     if (strpos($col, '`') !== false) {
         return PEAR::raiseError("Invalid email column name: '{$col}'", DATAFACE_E_WARNING);
     }
     $this->emailTable = $table = $action['email_table'];
     if (strpos($table, '`') !== false) {
         return PEAR::raiseError("Invalid email table name: '{$table}'", DATAFACE_E_WARNING);
     }
     $this->joinTable = $join_table = $query['-table'] . '__' . $table;
     $this->recipientsTable = $query['-table'];
     // The name of the table that tracks which records have had email sent.
     // Next make sure that the email table(s) exist(s)
     if (!Dataface_Table::tableExists($table, false) || !Dataface_Table::tableExists($join_table, false)) {
         $this->createEmailTables($table, $join_table);
     }
     $emailTableObj =& Dataface_Table::loadTable($this->emailTable);
     $contentField =& $emailTableObj->getField('content');
     $contentField['widget']['atts']['rows'] = 20;
     $contentField['widget']['atts']['cols'] = 60;
     $contentField['widget']['label'] = 'Message body';
     $contentField['widget']['description'] = 'Please enter your message content in plain text.';
     $contentField['widget']['type'] = 'htmlarea';
     $contentField['widget']['editor'] = 'nicEdit';
     $subjectField =& $emailTableObj->getField('subject');
     $subjectField['widget']['atts']['size'] = 60;
     $fromField =& $emailTableObj->getField('from');
     $fromField['widget']['atts']['size'] = 60;
     $fromField['widget']['description'] = 'e.g. Web Lite Solutions &lt;info@weblite.ca&gt;';
     $ccField =& $emailTableObj->getField('cc');
     $ccField['widget']['atts']['size'] = 60;
     $ignoreBlacklistField =& $emailTableObj->getField('ignore_blacklist');
     $ignoreBlacklistField['widget']['type'] = 'checkbox';
     $ignoreBlacklistField['widget']['description'] = 'The black list is a list of email addresses that have opted out of receiving email.  I.e. Users on the black list do not want to receive email.  Check this box if you want to send to blacklisted addresses despite their wish to be left alone.';
     $form = df_create_new_record_form($table);
     $form->_build();
     $form->addElement('hidden', '-action');
     $form->addElement('hidden', '-table');
     $form->setDefaults(array('-action' => $query['-action'], '-table' => $query['-table']));
     $form->insertElementBefore($form->createElement('checkbox', 'send_now', '', 'Send now (leave this box unchecked if you wish these emails to be queued for later sending by the daily cron job.  Recommended to leave this box unchecked for large found sets (&gt;100 records).)'), 'submit_new_newsletters_record');
     $form->addElement('hidden', '-query_string');
     $form->setDefaults(array('-query_string' => base64_encode(serialize($query))));
     if (@$app->_conf['from_email']) {
         $form->setDefaults(array('from' => $app->_conf['from_email']));
     }
     if ($form->validate()) {
         $res = $form->process(array(&$form, 'save'), true);
         if (PEAR::isError($res)) {
             return $res;
         }
         // The form saved ok.. so we can send the emails.
         //$resultSet = $app->getResultSet();
         //$resultSet->loadSet();
         //$it =& $resultSet->iterator();
         $vals = $form->exportValues();
         $q2 = unserialize(base64_decode($vals['-query_string']));
         //print_r($q2);
         //exit;
         $qb = new Dataface_QueryBuilder($query['-table'], $q2);
         $sql = "insert ignore into `{$join_table}` (recipient_email,messageid,date_created) select `" . $col . "`, '" . addslashes($form->_record->val('id')) . "' as messageid, now() as date_created " . $qb->_from() . " " . $qb->_secure($qb->_where());
         //echo $sql;exit;
         $sres = mysql_query($sql, df_db());
         if (!$sres) {
             trigger_error(mysql_error(df_db()), E_USER_ERROR);
         }
         //while ($row = mysql_fetch_row($sres) ){
         //	$join_rec = new Dataface_Record($join_table, array('messageid'=>$form->_record->val('id'),
         //													   'recipient_email'=>$row[0],
         //													   'date_created'=>date('Y-m-d h:i:s')));
         //	$res = $join_rec->save();
         //	if ( !$res ) return PEAR::raiseError("Failed to add entry for email '".$curr->val($col)."'", DATAFACE_E_WARNING);
         //	unset($join_rec);
         //	unset($curr);
         //}
         //$it = df_get_records($query['-table'], $q2);
         //while ( $it->hasNext() ){
         //	$curr =& $it->next();
         //	$join_rec = new Dataface_Record($join_table, array('messageid'=>$form->_record->val('id'),
         //													   'recipient_email'=>$curr->val($col),
         //													   'date_created'=>date('Y-m-d h:i:s')));
         //	$res = $join_rec->save();
         //	if ( !$res ) return PEAR::raiseError("Failed to add entry for email '".$curr->val($col)."'", DATAFACE_E_WARNING);
         //	unset($join_rec);
         //	unset($curr);
         //}
         //$this->messages = array();
         // If we're set to send the email right now
         //if ( $form->exportValue('send_now') ){
         //	$this->sendMail($form->_record->val('id'));
         //}
         $this->postJob($form->_record->val('id'), $this->emailTable, $this->joinTable, $this->recipientsTable, $this->emailColumn);
         //$this->messages[] = "Email has been queued for delivery.";
         //if ( count($this->messages) > 0 ){
         //$_SESSION['--msg'] = implode("\n",$this->messages);
         //echo $_SESSION['--msg'];
         //exit;
         //}
         $q2['-action'] = 'list';
         unset($q2['-limit']);
         header('Location: ' . $app->url($q2) . '&--msg=' . urlencode("The message has been queued for delivery"));
         exit;
     }
     $addresses = array();
     //$resultSet = $app->getResultSet();
     //$resultSet->loadSet();
     //$it =& $resultSet->iterator();
     //$it = df_get_records($query['-table'], array_merge($query, array('-limit'=>30)));
     //while ( $it->hasNext() ){
     //	$curr =& $it->next();
     //	$addresses[] = $curr->val($col);
     //
     //	unset($curr);
     //}
     ob_start();
     $form->display();
     $context = array();
     $context['email_form'] = ob_get_contents();
     $profileTable =& Dataface_Table::loadTable($query['-table']);
     $context['fields'] = array_keys($profileTable->fields(false, true, true));
     //$context['blacklist'] = $this->getBlackListed($addresses);
     //$context['addresses'] = array_diff($addresses, $context['blacklist']);
     ob_end_clean();
     df_register_skin('email', DATAFACE_PATH . '/modules/Email/templates');
     df_display($context, 'email_form.html');
 }
Example #9
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $table =& Dataface_Table::loadTable($query['-table']);
     $form = new HTML_QuickForm();
     foreach ($query as $key => $val) {
         if ($key[0] == '-' and $key[1] != '-') {
             $form->addElement('hidden', $key, $val);
         }
     }
     $form->addElement('hidden', '--redirect');
     $form->setDefaults(array('--redirect' => $app->url('')));
     $form->addElement('text', 'title', 'Title');
     $columns = array();
     $options = array($query['-table'] => $query['-table']);
     foreach ($table->relationships() as $rname => $relationship) {
         $options['::' . $rname] = '::' . $rname;
         $destTables = $relationship->getDestinationTables();
         $rfields = $relationship->fields(true);
         $fkeys = $relationship->getForeignKeyValues();
         //print_r($fkeys);
         $rcolumns = array();
         foreach ($rfields as $rfname) {
             list($rftable, $rfname) = explode('.', $rfname);
             if (isset($fkeys[$rftable][$rfname])) {
                 continue;
             }
             $columns['::' . $rname][$rname . '.' . $rfname] = $rname . '.' . $rfname;
         }
         //foreach ($destTables as $destTable){
         //
         //	foreach ($destTable->relationships() as $destRelationshipName => $destRelationship ){
         //		$options['::'.$rname.'::'.$destRelationshipName] = '::'.$rname.'::'.$destRelationshipName;
         //
         //	}
         //	unset($destTable);
         //}
     }
     $form->addElement('select', 'table', 'From table', $options, array('onchange' => 'Dataface.modules.DataGrid.newForm.updateFieldsOptions(this);'));
     $options = array();
     foreach ($table->fields() as $fieldName => $fieldDef) {
         $options[$fieldName] = $fieldName;
     }
     $columns[$query['-table']] = $options;
     $fieldSelector =& $form->addElement('advmultiselect', 'fields', 'Selected Columns', $options);
     $fieldSelector->setButtonAttributes('moveup', 'class=inputCommand');
     $fieldSelector->setButtonAttributes('movedown', 'class=inputCommand');
     $form->addElement('submit', 'submit', 'Create Grid');
     if ($form->validate()) {
         $res = $form->process(array(&$this, 'process'), true);
         if (PEAR::isError($res)) {
             return $res;
         }
         if (@$query['--redirect']) {
             $url = $query['--redirect'];
         } else {
             $url = $app->url('');
         }
         $url = preg_replace('/[&]--[^=]+\\=[^&]*/', '', $url);
         $url .= '&--msg=' . urlencode('Grid Saved Successfully');
         header('Location: ' . $url);
         exit;
     }
     import('HTML/QuickForm/Renderer/ArraySmarty.php');
     import('Dataface/SkinTool.php');
     $renderer = new HTML_QuickForm_Renderer_ArraySmarty(Dataface_SkinTool::getInstance());
     $form->accept($renderer);
     df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
     $json = new Services_JSON();
     df_display(array('form' => $renderer->toArray(), 'columns' => $json->encode($columns)), 'DataGrid/new.html');
 }
Example #10
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $mt =& Dataface_ModuleTool::getInstance();
     $mod =& $mt->loadModule('modules_DataGrid');
     if (PEAR::isError($mod)) {
         return $mod;
     }
     $dataGrid = $mod->getDataGrid($query['-gridid']);
     if (!$dataGrid) {
         return PEAR::raiseError("Error, the specified data grid could not be found");
     }
     import('Dataface/XMLTool.php');
     $xmlTool = new Dataface_XMLTool();
     $records = df_get_records_array($query['-table'], $query, null, null, false);
     $rows = array();
     $fieldDefs = $dataGrid->getFieldDefs();
     foreach ($records as $record) {
         $row = array();
         $row['__recordID__'] = $record->getId();
         foreach ($fieldDefs as $colName => $fieldDef) {
             if (strpos($colName, '#') === false) {
                 // No index was provided so index is 0
                 $index = 0;
                 $fieldName = $colName;
             } else {
                 list($fieldName, $index) = explode('#', $colName);
             }
             $row[str_replace('.', '-', $colName)] = $xmlTool->xmlentities($record->strval($fieldName, $index));
         }
         $rows[] = $row;
         unset($record);
     }
     if (@$_GET['--format'] == 'csv') {
         import('actions/export_csv.php');
         $temp = tmpfile();
         $headings = array();
         if ($rows) {
             foreach ($fieldDefs as $key => $val) {
                 $headings[] = $val['widget']['label'];
             }
         }
         fputcsv($temp, $headings, ",", '"');
         foreach ($rows as $row) {
             $thisrow = array();
             foreach ($row as $key => $val) {
                 if ($key != '__recordID__') {
                     $thisrow[] = $val;
                 }
             }
             fputcsv($temp, $thisrow, ",", '"');
         }
         fseek($temp, 0);
         header("Content-type: text/csv; charset=" . $app->_conf['oe']);
         header('Content-disposition: attachment; filename="' . $query['-table'] . '_' . $dataGrid->name . '_export_' . date('Y_m_d_H_i_s') . '.csv"');
         $fstats = fstat($temp);
         echo fread($temp, $fstats['size']);
         fclose($temp);
     } else {
         header("Content-type: application/xml; charset=" . $app->_conf['oe']);
         df_register_skin('DataGrid', DATAFACE_PATH . '/modules/DataGrid/templates');
         df_display(array('rows' => &$rows), 'DataGrid/datastore.xml');
     }
     exit;
 }