Exemplo n.º 1
0
 public function run()
 {
     $res = $this->response;
     $status = 400;
     $message = 'fill-all-fields';
     $data = null;
     $icons = \Car\Offer::get_attr_options('icon');
     $opts = array();
     foreach ($icons as $icon) {
         $opts[] = array('value' => $icon, 'name' => $icon);
     }
     $ident = $this->ident;
     def($ident, null);
     $f = $res->form(array('use_comm' => true));
     $f->input(array('type' => 'text', 'name' => 'driver', 'required' => true));
     $f->input(array('type' => 'text', 'name' => 'from', 'required' => true));
     $f->input(array('type' => 'number', 'name' => 'seats', 'min' => 1, 'required' => true));
     $f->input(array('type' => 'datetime', 'name' => 'departure', 'required' => true));
     $f->input(array('type' => 'select', 'name' => 'icon', 'required' => true, 'options' => $opts));
     $f->input(array('name' => 'phone', 'type' => 'phone', 'required' => true));
     $f->input(array('type' => 'email', 'name' => 'email', 'required' => true));
     $f->input(array('type' => 'textarea', 'name' => 'desc', 'required' => false));
     if ($f->submited()) {
         if ($f->passed()) {
             $attrs = $f->get_data();
             $status = 200;
             $message = 'saved';
             if ($ident) {
                 $item = \Car\Offer::get_first()->where(array('ident' => $ident))->fetch();
                 if (!$item) {
                     throw new \System\Error\NotFound();
                 }
             } else {
                 $item = new \Car\Offer();
             }
             $item->update_attrs($attrs);
             $item->visible = true;
             $item->save();
             if (!$item->sent_notif) {
                 $item->send_notif($res);
             }
             $data = $item->get_data();
         } else {
             $data = $f->get_errors();
         }
         $res->mime = 'text/html';
         if (!isset($ident) || $f->submited()) {
             $this->json_response($status, $message, $data);
         }
     }
 }
Exemplo n.º 2
0
 public function run()
 {
     $this->req('ident');
     $offer = \Car\Offer::get_first()->where(array('ident' => $this->ident, 'visible' => true))->fetch();
     if ($offer) {
         $cfg = $this->request->fconfig;
         $cfg['ui']['data'] = array(array('model' => 'Car.Offer', 'items' => array($offer->to_object_with_perms($this->request->user))));
         $this->request->fconfig = $cfg;
         $this->response->subtitle = 'úpravy nabídky na sdílení auta';
         $this->partial('car/admin/form', array("item" => $offer, "requests" => $offer->requests->fetch()));
     } else {
         throw new \System\Error\NotFound();
     }
 }
Exemplo n.º 3
0
 public function run()
 {
     $data = $this->dbus->get_data('admin');
     $offer = null;
     if (isset($data['offer'])) {
         $offer = $data['offer'];
     }
     if (!$offer) {
         $id = $this->req('id');
         $offer = \Car\Offer::get_first()->where(array('id_car_offer' => $id, 'visible' => true))->fetch();
     }
     if ($offer) {
         $this->response->subtitle = $offer->driver . ' vás zve na cestu na Improtřesk 2016';
         $this->partial('car/offer-detail', array("item" => $offer, "free" => $offer->seats - $offer->requests->where(array('status' => 2))->count(), "show_form" => !!$this->show_form, "show_rq" => true, "requests" => $offer->requests->where(array('status' => array(1, 2)))->fetch()));
     } else {
         throw new \System\Error\NotFound();
     }
 }
Exemplo n.º 4
0
 public function run()
 {
     $rq = $this->request;
     $res = $this->response;
     $ident = $this->req('ident');
     $offer = \Car\Offer::get_first()->where(array('ident' => $ident, 'visible' => true))->fetch();
     if ($offer) {
         $cfg = $rq->fconfig;
         $cfg['ui']['data'] = array(array('model' => 'Car.Offer', 'items' => array($offer->to_object_with_perms($rq->user))));
         $rq->fconfig = $cfg;
         $res->subtitle = 'úpravy nabídky na sdílení auta';
         $this->propagate('offer', $offer);
         $this->propagate('id', $offer->id);
         $this->partial('car/admin/links', array("ident" => $ident, "slot" => 'detail'));
     } else {
         throw new \System\Error\NotFound();
     }
 }