Ejemplo n.º 1
0
 function handle(&$params)
 {
     $app =& Dataface_Application::getInstance();
     $query =& $app->getQuery();
     $nav = array('prev' => array('label' => null, 'url' => null), 'next' => array('label' => null, 'url' => null), 'current' => array('label' => null));
     import('Dataface/Ontology.php');
     Dataface_Ontology::registerType('Event', 'Dataface/Ontology/Event.php', 'Dataface_Ontology_Event');
     $ontology =& Dataface_Ontology::newOntology('Event', $query['-table']);
     $dateAtt = $ontology->getFieldname('date');
     if (PEAR::isError($dateAtt)) {
         die($dateAtt->getMessage());
     }
     if (!isset($query[$dateAtt]) or !preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}\\.\\.[0-9]{4}-[0-9]{2}-[0-9]{2}$/', $query[$dateAtt])) {
         $query[$dateAtt] = date('Y-m-01') . '..' . date('Y-m-t');
     }
     list($startDate) = explode('..', $query[$dateAtt]);
     $startTime = strtotime($startDate);
     $prevMonth = intval(date('m', $startTime)) - 1;
     $nextMonth = intval(date('m', $startTime)) + 1;
     $prevTime = mktime(0, 0, 0, $prevMonth, 1, date('Y', $startTime));
     $nextTime = mktime(0, 0, 0, $nextMonth, 1, date('Y', $startTime));
     $nav['prev']['label'] = date('F Y', $prevTime);
     $nav['prev']['url'] = $app->url('-action=calendar&' . $dateAtt . '=' . urlencode(date('Y-m-01', $prevTime) . '..' . date('Y-m-t', $prevTime)), true, true);
     $nav['next']['label'] = date('F Y', $nextTime);
     $nav['next']['url'] = $app->url('-action=calendar&' . $dateAtt . '=' . urlencode(date('Y-m-01', $nextTime) . '..' . date('Y-m-t', $nextTime)), true, true);
     $nav['current']['label'] = date('F Y', $startTime);
     $query['-limit'] = 500;
     $records =& df_get_records_array($query['-table'], $query);
     $events = array();
     foreach ($records as $record) {
         $event = $ontology->newIndividual($record);
         $datems = strtotime(date('Y-m-d', strtotime($event->strval('date')))) * 1000;
         $timems = (strtotime(date('H:i:s', strtotime($event->strval('start')))) - strtotime(date('Y-m-d'))) * 1000;
         $events[] = array('title' => $record->getTitle(), 'description' => $record->getDescription(), 'date' => $datems + $timems, 'startTime' => strtotime($event->strval('date')) * 1000, 'record_id' => $record->getId());
         unset($event);
         unset($record);
     }
     import('Services/JSON.php');
     $json = new Services_JSON();
     $event_data = 'var events = ' . $json->encode($events);
     import('Dataface/ResultList.php');
     $rs = new Dataface_ResultList($query['-table']);
     df_display(array('event_data' => $event_data, 'nav' => &$nav, 'currentTime' => $startTime, 'filters' => $rs->getResultFilters()), 'Dataface_Calendar.html');
 }
Ejemplo n.º 2
0
 function handle(&$params)
 {
     $this->params =& $params['action'];
     unset($params);
     $params =& $this->params;
     Dataface_PermissionsTool::getInstance()->setDelegate(new dataface_actions_register_permissions_delegate());
     $app =& Dataface_Application::getInstance();
     $auth =& Dataface_AuthenticationTool::getInstance();
     import('Dataface/Ontology.php');
     Dataface_Ontology::registerType('Person', 'Dataface/Ontology/Person.php', 'Dataface_Ontology_Person');
     $this->ontology =& Dataface_Ontology::newOntology('Person', $app->_conf['_auth']['users_table']);
     $atts =& $this->ontology->getAttributes();
     $query =& $app->getQuery();
     if (!is_array(@$app->_conf['_auth'])) {
         return PEAR::raiseError("Cannot register when authentication is not enabled.", DATAFACE_E_ERROR);
     }
     if (isset($app->_conf['_auth']['email_column'])) {
         $atts['email'] =& $this->ontology->table->getField($app->_conf['_auth']['email_column']);
         $this->fieldnames['email'] = $app->_conf['_auth']['email_column'];
     }
     if ($auth->isLoggedIn()) {
         return Dataface_Error::permissionDenied("Sorry you cannot register once you are logged in.  If you want to register, you must first log out.");
     }
     if (!@$app->_conf['_auth']['allow_register']) {
         return PEAR::raiseError("Sorry, registration is not allowed.  Please contact the administrator for an account.", DATAFACE_E_ERROR);
     }
     $pt =& Dataface_PermissionsTool::getInstance();
     // Create a new record form on the users table
     $this->form =& df_create_new_record_form($app->_conf['_auth']['users_table']);
     // add the -action element so that the form will direct us back here.
     $this->form->addElement('hidden', '-action');
     $this->form->setDefaults(array('-action' => $query['-action']));
     // Check to make sure that there isn't another user with the same
     // username already.
     $validationResults = $this->validateRegistrationForm($_POST);
     if (count($_POST) > 0 and PEAR::isError($validationResults)) {
         $app->addMessage($validationResults->getMessage());
         $this->form->_errors[$app->_conf['_auth']['username_column']] = $validationResults->getMessage();
     }
     if (!PEAR::isError($validationResults) and $this->form->validate()) {
         // The form input seems OK.  Let's process the form
         // Since we will be using our own form processing for this action,
         // we need to manually push the field inputs into the Dataface_Record
         // object.
         $this->form->push();
         // Now we obtain the Dataface_Record object that is to be added.
         $rec =& $this->form->_record;
         $delegate =& $rec->_table->getDelegate();
         // Give the delegate classes an opportunity to have some fun
         if (isset($delegate) and method_exists($delegate, 'beforeRegister')) {
             $res = $delegate->beforeRegister($rec);
             if (PEAR::isError($res)) {
                 return $res;
             }
         }
         $appdel =& $app->getDelegate();
         if (isset($appdel) and method_exists($appdel, 'beforeRegister')) {
             $res = $appdel->beforeRegister($rec);
             if (PEAR::isError($res)) {
                 return $res;
             }
         }
         // This is where we actually do the processing.  This passes control
         // to the processRegistrationForm method in this class.
         $res = $this->form->process(array(&$this, 'processRegistrationForm'), true);
         // If there was an error in processing mark the error, and show the
         // form again.  Otherwise we just redirect to the next page and
         // let the user know that he was successful.
         if (PEAR::isError($res)) {
             $app->addError($res);
         } else {
             // Let the delegate classes perform their victory lap..
             if (isset($delegate) and method_exists($delegate, 'afterRegister')) {
                 $res = $delegate->afterRegister($rec);
                 if (PEAR::isError($res)) {
                     return $res;
                 }
             }
             if (isset($appdel) and method_exists($appdel, 'afterRegister')) {
                 $res = $appdel->afterRegister($rec);
                 if (PEAR::isError($res)) {
                     return $res;
                 }
             }
             // We accept --redirect markers to specify which page to redirect
             // to after we're done.  This will usually be the page that the
             // user was on before they went to the login page.
             if (isset($_SESSION['--redirect'])) {
                 $url = $_SESSION['--redirect'];
             } else {
                 if (isset($_SESSION['-redirect'])) {
                     $url = $_SESSION['-redirect'];
                 } else {
                     if (isset($_REQUEST['--redirect'])) {
                         $url = $_REQUEST['--redirect'];
                     } else {
                         if (isset($_REQUEST['-redirect'])) {
                             $url = $_REQUEST['-redirect'];
                         } else {
                             $url = $app->url('-action=' . $app->_conf['default_action']);
                         }
                     }
                 }
             }
             if (@$params['email_validation']) {
                 $individual = $this->ontology->newIndividual($this->form->_record);
                 $msg = df_translate('actions.register.MESSAGE_THANKYOU_PLEASE_VALIDATE', 'Thank you. An email has been sent to ' . $individual->strval('email') . ' with instructions on how to complete the registration process.', array('email' => $individual->strval('email')));
             } else {
                 // To save the user from having to log in after he has just filled
                 // in the registration form, we will just log him in right here.
                 $_SESSION['UserName'] = $this->form->exportValue($app->_conf['_auth']['username_column']);
                 $msg = df_translate('actions.register.MESSAGE_REGISTRATION_SUCCESSFUL', "Registration successful.  You are now logged in.");
             }
             // Now we actually forward to the success page along with a success message
             if (strpos($url, '?') === false) {
                 $url .= '?';
             }
             $app->redirect($url . '&--msg=' . urlencode($msg));
         }
     }
     // We want to display the form, but not yet so we will use an output buffer
     // to store the form HTML in a variable and pass it to our template.
     ob_start();
     $this->form->display();
     $out = ob_get_contents();
     ob_end_clean();
     $context = array('registration_form' => $out);
     // We don't want to keep the registration page in history, because we want to
     // be able to redirect the user back to where he came from before registering.
     $app->prefs['no_history'] = true;
     df_display($context, 'Dataface_Registration.html');
 }
Ejemplo n.º 3
0
 function getEmailColumn()
 {
     if (!isset($this->emailColumn)) {
         import('Dataface/Ontology.php');
         Dataface_Ontology::registerType('Person', 'Dataface/Ontology/Person.php', 'Dataface_Ontology_Person');
         $ontology = Dataface_Ontology::newOntology('Person', $this->usersTable);
         if (isset($this->conf['email_column'])) {
             $this->emailColumn = $this->conf['email_column'];
         } else {
             $this->emailColumn = $ontology->getFieldname('email');
         }
     }
     return $this->emailColumn;
 }