Exemplo n.º 1
0
 /**
  * Page with a form to create a new ticket.
  */
 protected function actionNewTicket()
 {
     // Check for the user to be logged in and check if it is allowed to use anonymous ticket creation
     if (!\GO::user() && GOS::site()->config->tickets_allow_anonymous !== true) {
         throw new \GO\Base\Exception\AccessDenied();
     }
     // Create a new ticket object
     $ticket = new \GO\Tickets\Model\Ticket();
     // Check if the user is logged in.
     if (\GO::user()) {
         // Find the contact model of the current user.
         $contact = \GO::user()->contact;
         // Set the ticketfields values from the contact model.
         if ($contact) {
             $ticket->setFromContact($contact);
         }
     }
     if (isset($_GET['type_id'])) {
         $ticket->type_id = $_GET['type_id'];
     }
     // Create a new message object
     $message = new \GO\Tickets\Model\Message();
     // Create an instance of the uploader
     $uploader = new \GO\Site\Widgets\Uploader('uploader', $_REQUEST, 'createticket');
     // Authorize the uploader to handle the uploaded files
     \GO\Base\Authorized\Actions::setAuthorized('plupload');
     // enable ACL
     \GO::setIgnoreAclPermissions(false);
     // Retreive the tickettypes for showing in the dropdownlist
     if (!\GO::user()) {
         $ticketTypes = \GO\Tickets\Model\Type::model()->find(\GO\Base\Db\FindParams::newInstance()->criteria(\GO\Base\Db\FindCriteria::newInstance()->addCondition('publish_on_site', true))->order('name')->ignoreAcl());
     } else {
         $ticketTypes = \GO\Tickets\Model\Type::model()->find(\GO\Base\Db\FindParams::newInstance()->order('name'));
     }
     // disable ACL again
     \GO::setIgnoreAclPermissions(true);
     // Check for the form post
     if (\GO\Base\Util\Http::isPostRequest()) {
         // Set the ticket attributes
         $ticket->setAttributes($_POST['Ticket']);
         // Try to save the ticket
         if ($ticket->save()) {
             // Add the posted attributes to the message object
             $message->setAttributes($_POST['Message']);
             // If the ticket is closed by the user
             if (isset($_POST['CloseTicket'])) {
                 $message->setStatus(\GO\Tickets\Model\Ticket::STATUS_CLOSED);
             }
             // Add a message to the ticket.
             if ($ticket->addMessage($message)) {
                 // If saving is OK then redirect to the ticket page
                 $this->redirect(array('/tickets/site/showTicket', 'ticket_number' => $ticket->ticket_number, 'ticket_verifier' => $ticket->ticket_verifier));
             }
         }
     }
     // Render the ticket page
     $this->render("ticket", array('ticket' => $ticket, 'message' => $message, 'uploader' => $uploader, 'ticketTypes' => $ticketTypes));
 }
Exemplo n.º 2
0
 protected function actionProfile()
 {
     $user = \GO::user();
     $contact = $user->contact;
     //set additional required fields
     $contact->setValidationRule('address', 'required', true);
     $contact->setValidationRule('zip', 'required', true);
     $contact->setValidationRule('city', 'required', true);
     //		$user->setValidationRule('passwordConfirm', 'required', false);
     $user->setValidationRule('password', 'required', false);
     \GO::config()->password_validate = false;
     if ($contact->company) {
         $company = $contact->company;
     } else {
         $company = new \GO\Addressbook\Model\Company();
         $company->addressbook_id = $contact->addressbook_id;
     }
     if (\GO\Base\Util\Http::isPostRequest()) {
         if (!empty($_POST['currentPassword']) && !empty($_POST['User']['password'])) {
             if (!$user->checkPassword($_POST['currentPassword'])) {
                 GOS::site()->notifier->setMessage('error', "Huidig wachtwoord onjuist");
                 unset($_POST['User']['password']);
                 unset($_POST['User']['passwordConfirm']);
             }
         } else {
             unset($_POST['User']['password']);
             unset($_POST['User']['passwordConfirm']);
         }
         $user->setAttributes($_POST['User']);
         $contact->setAttributes($_POST['Contact']);
         $company->setAttributes($_POST['Company']);
         $company->checkVatNumber = true;
         if (!empty($_POST['Company']['postAddressIsEqual'])) {
             $company->setPostAddressFromVisitAddress();
         }
         if (!GOS::site()->notifier->hasMessage('error') && $user->validate() && $contact->validate() && $company->validate()) {
             \GO::setIgnoreAclPermissions();
             //allow guest to create user
             $user->save();
             $company->save();
             $contact->company_id = $company->id;
             $contact->save();
             GOS::site()->notifier->setMessage('success', GOS::t('formEditSuccess'));
         } else {
             GOS::site()->notifier->setMessage('error', "Please check the form for errors");
         }
     }
     $company->post_address_is_address = false;
     if ($company->address == $company->post_address && $company->address_no == $company->post_address_no && $company->city == $company->post_city) {
         $company->post_address_is_address = true;
     }
     //clear values for form
     $user->password = "";
     $user->passwordConfirm = "";
     echo $this->render('profile', array('user' => $user, 'contact' => $contact, 'company' => $company));
 }