Exemple #1
0
 public function build($runData)
 {
     $pl = $runData->getParameterList();
     $email = $pl->getParameterValue("email", 'MODULE', 'AMODULE');
     $format = $pl->getParameterValue("module_body", 'MODULE', 'AMODULE');
     $title = $pl->getParameterValue("title", 'MODULE', 'AMODULE');
     $successPage = $pl->getParameterValue("successPage", 'MODULE', 'AMODULE');
     $outputFormat = $pl->getParameterValue("format", 'MODULE', 'AMODULE');
     // check if email is ok
     if (strlen($email) < 5 || strlen($email) > 50 || preg_match("/^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)+\$/", $email) == 0) {
         throw new ProcessException(_('Please provide a valid email address via the email="*****@*****.**" parameter.'));
     }
     // check if title is valid
     if ($title && strlen8($title) > 200) {
         throw new ProcessException(_('The title="..." attribute is not valid.'));
     }
     // parse the format
     $fields = MailFormUtils::parseFormat($format);
     //stringify fields too...
     $runData->contextAdd("fields", $fields);
     $runData->contextAdd("rand", rand(1, 100000));
     // save fields!
     $parmArray = $pl->asArray();
     $key = md5(serialize($parmArray)) . '_' . time();
     DatabaseStorage::instance()->set($key, array('email' => $email, 'fields' => $fields, 'title' => $title, 'successPage' => $successPage, 'format' => $outputFormat), 3600);
     $runData->contextAdd("fkey", $key);
 }
Exemple #2
0
 public static function instance()
 {
     if (!self::$instance) {
         self::$instance = new DatabaseStorage();
     }
     return self::$instance;
 }
 private function put()
 {
     PHPWS_Core::initModClass('intern', 'Faculty.php');
     //$postarray = json_decode(file_get_contents('php://input'), true);
     $req = Server::getCurrentRequest();
     $postarray = json_decode($req->getRawData(), true);
     $faculty = new FacultyDB();
     $faculty->setId($postarray['id']);
     $faculty->setUsername($postarray['username']);
     $faculty->setFirstName($postarray['first_name']);
     $faculty->setLastName($postarray['last_name']);
     $faculty->setPhone($postarray['phone']);
     $faculty->setFax($postarray['fax']);
     $faculty->setStreetAddress1($postarray['street_address1']);
     $faculty->setStreetAddress2($postarray['street_address2']);
     $faculty->setCity($postarray['city']);
     $faculty->setState($postarray['state']);
     $faculty->setZip($postarray['zip']);
     // Save the faculty object
     PHPWS_Core::initModClass('intern', 'DatabaseStorage.php');
     try {
         DatabaseStorage::saveObject($faculty);
     } catch (Exception $e) {
         header('HTTP/1.1 500 Internal Server Error');
         exit;
     }
     echo json_encode($faculty->extractVars());
     // Exit, since this is called by JSON
     exit;
 }
 public function execute()
 {
     // Get data from request
     $internshipId = $_REQUEST['internshipId'];
     $name = $_REQUEST['emergency_contact_name'];
     $relation = $_REQUEST['emergency_contact_relation'];
     $phone = $_REQUEST['emergency_contact_phone'];
     // Sanity checking
     if (is_null($internshipId) || !isset($internshipId)) {
         throw new InvalidArgumentException('Missing internship ID.');
     }
     if (is_null($name) || !isset($name)) {
         throw new InvalidArgumentException('Missing contact name.');
     }
     if (is_null($relation) || !isset($relation)) {
         throw new InvalidArgumentException('Missing contact relationship.');
     }
     if (is_null($phone) || !isset($phone)) {
         throw new InvalidArgumentException('Missing contact phone number.');
     }
     PHPWS_Core::initModClass('intern', 'EmergencyContact.php');
     PHPWS_Core::initModClass('intern', 'InternshipFactory.php');
     // Get an Internship object based on the ID
     $internship = InternshipFactory::getInternshipById($internshipId);
     // Create the emergency contact
     $contact = new EmergencyContact($internship, $name, $relation, $phone);
     // Save the emergency contact object
     PHPWS_Core::initModClass('intern', 'DatabaseStorage.php');
     DatabaseStorage::save($contact);
     echo json_encode($contact);
     // Exit, since this is called by JSON
     //TODO
     exit;
 }
 public function run()
 {
     DatabaseStorage::instance()->clean();
 }
Exemple #6
0
 public function sendFormEvent($runData)
 {
     $pl = $runData->getParameterList();
     $values = $pl->getParameterValue("formdata");
     $json = new JSONService(SERVICES_JSON_LOOSE_TYPE);
     $values = $json->decode($values);
     $site = $runData->getTemp("site");
     $fkey = trim($pl->getParameterValue("formdef"));
     $data = DatabaseStorage::instance()->get($fkey);
     if (!$data) {
         throw new ProcessException(_("No form definition found."));
     }
     $fields = $data['fields'];
     $email = $data['email'];
     $title = $data['title'];
     $format = strtolower(trim($data['format']));
     if (!in_array($format, array('csv'))) {
         $format = null;
     }
     // parse and validate!
     $errors = array();
     foreach ($fields as &$field) {
         $name = $field['name'];
         $value = $values[$field['name']];
         $field['value'] = $value;
         // check if need to validate. any rules?
         // first, if select, can not be empty
         if ($field['type'] == "select") {
             if (!$value) {
                 $errors[$name] = _('Please select an option');
                 continue;
             }
         }
         if ($field['rules'] && is_array($field['rules'])) {
             foreach ($field['rules'] as $ruleName => $ruleValue) {
                 switch ($ruleName) {
                     case 'required':
                         if ($value == "") {
                             $errors[$name] = _('Please enter this information');
                             break 2;
                         }
                         break;
                     case 'minLength':
                         if (strlen8($value) < $ruleValue) {
                             $errors[$name] = _('Value is too short');
                             break 2;
                         }
                         break;
                     case 'maxLength':
                         if (strlen8($value) > $ruleValue) {
                             $errors[$name] = _('Value is too long');
                             break 2;
                         }
                         break;
                     case 'match':
                         if (!preg_match($ruleValue, $value)) {
                             $errors[$name] = _('Value is not valid');
                             break 2;
                         }
                         break;
                     case 'number':
                         if (!is_numeric($value)) {
                             $errors[$name] = _('Value is not numeric');
                             break 2;
                         }
                         break;
                     case 'minValue':
                         if (!is_numeric($value) || 1 * $value < 1 * $ruleValue) {
                             $errors[$name] = _('Value is too small');
                             break 2;
                         }
                         break;
                     case 'maxValue':
                         if (!is_numeric($value) || 1 * $value > 1 * $ruleValue) {
                             $errors[$name] = _('Value is too large');
                             break 2;
                         }
                         break;
                 }
             }
         }
         // fix checkboxes
         if ($field['type'] == "checkbox") {
             if (!$value) {
                 $field['value'] = _('No');
             } else {
                 $field['value'] = _('Yes');
             }
         }
     }
     if (count($errors)) {
         // "sir, we have some errors here. shit."
         $runData->ajaxResponseAdd("errors", $errors);
         throw new ProcessException("Form errors.", "form_errors");
     }
     $title = $title ? $title : sprintf(_("[%s] MailForm form data"), GlobalProperties::$SERVICE_NAME);
     $oe = new OzoneEmail();
     $oe->addAddress($email);
     $oe->setSubject($title);
     $oe->contextAdd('fields', $fields);
     $oe->contextAdd('values', $values);
     switch ($format) {
         case 'csv':
             $emailTemplate = 'wiki/mailform/MailFormCSV';
             // fix the values (escape)
             foreach ($fields as &$field) {
                 $value = $field['value'];
                 if (preg_match("/[,\"\n]/", $value)) {
                     $value = str_replace('"', '""', $value);
                     $value = '"' . $value . '"';
                     $field['value'] = $value;
                 }
             }
             break;
         default:
             $emailTemplate = 'wiki/mailform/MailForm';
             break;
     }
     $oe->setBodyTemplate($emailTemplate);
     if (!$oe->Send()) {
         throw new ProcessException(_("The form data could not be sent to the specified email address."), "email_failed");
     }
     // ok, is there any success page?
     $successPage = $data['successPage'];
     if ($successPage) {
         $successPage = WDStringUtils::toUnixName($successPage);
         $page = DB_PagePeer::instance()->selectByName($site->getSiteId(), $successPage);
         if ($page) {
             $runData->ajaxResponseAdd("successPage", $successPage);
         }
     }
     if (GlobalProperties::$UI_SLEEP) {
         sleep(1);
     }
 }