Esempio n. 1
0
 private function _add()
 {
     use_helper('Validate');
     $data = $_POST['offer'];
     Flash::set('offer_postdata', $data);
     // Add pre-save checks here
     $errors = false;
     // CSRF checks
     if (isset($_POST['csrf_token'])) {
         $csrf_token = $_POST['csrf_token'];
         if (!SecureToken::validateToken($csrf_token, BASE_URL . 'offer/add')) {
             Flash::set('error', __('Invalid CSRF token found!'));
             redirect(get_url('offer/add'));
         }
     } else {
         Flash::set('error', __('No CSRF token found!'));
         redirect(get_url('offer/add'));
     }
     if (empty($data['name'])) {
         Flash::set('error', __('You have to specify a offer name!'));
         redirect(get_url('offer/add'));
     }
     if ($errors !== false) {
         // Set the errors to be displayed.
         Flash::set('error', implode('<br/>', $errors));
         redirect(get_url('offer/add'));
     }
     $new_offer = new Offer($data);
     $new_offer->created_by_id = AuthUser::getId();
     $new_offer->created_on = date('Y-m-d H:i:s');
     if ($new_offer->save()) {
         if (isset($_FILES)) {
             if (strlen($_FILES['upload_file']['name']) > 0 || strlen($_FILES['upload_file_home']['name']) > 0) {
                 $offer_id = $new_offer->lastInsertId();
                 $overwrite = false;
                 if (strlen($_FILES['upload_file']['name']) > 0) {
                     $file = $this->upload_pdf_file($offer_id, $_FILES['upload_file']['name'], FILES_DIR . '/offer/images/', $_FILES['upload_file']['tmp_name'], $overwrite);
                 }
                 if (strlen($_FILES['upload_file_home']['name']) > 0) {
                     $file2 = $this->upload_pdf_file2($offer_id, $_FILES['upload_file_home']['name'], FILES_DIR . '/offer/home/', $_FILES['upload_file_home']['tmp_name'], $overwrite);
                 }
                 if ($file === false || $file2 === false) {
                     Flash::set('error', __('File has not been uploaded!'));
                 }
                 redirect(get_url('offer/edit/' . $new_offer->id));
             }
         }
         Flash::set('success', __('Offer has been added!'));
         Observer::notify('offer_after_add', $new_offer->name);
         // save and quit or save and continue editing?
         if (isset($_POST['commit'])) {
             redirect(get_url('offer'));
         } else {
             redirect(get_url('offer/edit/' . $new_offer->id));
         }
     } else {
         Flash::set('error', __('Offer has not been added!'));
         redirect(get_url('offer/add'));
     }
 }
Esempio n. 2
0
 public function create()
 {
     $uid = Input::get('uid');
     $offer = new Offer();
     $offer->body = Input::get('body');
     $offer->recipient_id = $uid;
     $offer->rate = Input::get('rate') / 100;
     $offer->daily_rate = $offer->rate / 100 / Config::get('rate.days');
     $offer->offer_ends = Input::get('end_date');
     $offer->save();
     $recipient = DB::table('users')->where('id', '=', $uid)->first();
     $username = $recipient->email;
     $data = ['username' => $username, 'body' => Input::get('body')];
     Mail::send('emails.adminmessage', $data, function ($message) {
         $recipient = DB::table('users')->where('id', '=', Input::get('uid'))->first();
         $message->to($recipient->email, 'test')->subject('Offer');
     });
     return Redirect::to('/user/admin/nextstepusers');
 }
Esempio n. 3
0
 public function action_new_post()
 {
     if (Auth::guest()) {
         $page = Input::get('offer_type') == 1 ? 'offers/new_freight' : 'offers/new_trans';
         Cookie::put('rid', $page);
         return Redirect::to('login')->with_input();
     }
     $input = array('user_id' => Input::get('user_id'), 'offer_type' => Input::get('offer_type'), 'from_date' => $this->mysql_date(Input::get('from_date')), 'to_date' => $this->mysql_date(Input::get('to_date')), 'from_country' => Input::get('from_country'), 'from_state' => Input::get('from_state'), 'from_town' => Input::get('from_town'), 'to_country' => Input::get('to_country'), 'to_state' => Input::get('to_state'), 'to_town' => Input::get('to_town'), 'auto_type' => Input::get('auto_type'), 'auto_load_type' => Input::get('auto_load_type'), 'auto_capacity' => Input::get('auto_capacity'), 'auto_volume' => Input::get('auto_volume'), 'auto_price' => Input::get('auto_price'), 'auto_count' => Input::get('auto_count'), 'auto_license' => Input::get('auto_license'), 'comments' => Input::get('comments'));
     $rules = array('offer_type' => 'required', 'from_date' => 'required', 'to_date' => 'required', 'from_country' => 'required', 'from_town' => 'required', 'to_country' => 'required', 'to_town' => 'required', 'auto_type' => 'required', 'auto_capacity' => 'numeric|required', 'auto_count' => 'integer', 'auto_price' => 'numeric');
     $v = Validator::make($input, $rules);
     if ($v->fails()) {
         $page = $input['offer_type'] == 1 ? 'offers/new_freight' : 'offers/new_trans';
         return Redirect::to($page)->with_errors($v)->with_input();
     } else {
         $offer = new Offer($input);
         $offer->save();
         return View::make('sapoc.pages.result')->with('message', __('offers-new.save-success'));
     }
 }
Esempio n. 4
0
 /**
  * Store a newly created offer in storage.
  *
  * @return Response
  */
 public function store()
 {
     $order = Input::get('order');
     $company = Input::get('company');
     $amounts = Input::get('amount');
     $prices = Input::get('price');
     $dates = Input::get('date');
     foreach ($dates as $number => $date) {
         if (!empty($amounts[$number]) && !empty($prices[$number])) {
             $offer = new Offer();
             $offer->provider_id = Auth::user()->provider_id;
             $offer->order_id = $order;
             $offer->date = $date;
             $offer->amount = $amounts[$number];
             $offer->price = $prices[$number];
             $offer->state = "pending";
             $offer->save();
         }
     }
     return Redirect::route('orders_for.product', [$company, $order]);
 }
Esempio n. 5
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aOffer !== null) {
             if ($this->aOffer->isModified() || $this->aOffer->isNew()) {
                 $affectedRows += $this->aOffer->save($con);
             }
             $this->setOffer($this->aOffer);
         }
         if ($this->aType !== null) {
             if ($this->aType->isModified() || $this->aType->isNew()) {
                 $affectedRows += $this->aType->save($con);
             }
             $this->setType($this->aType);
         }
         if ($this->aTypology !== null) {
             if ($this->aTypology->isModified() || $this->aTypology->isNew()) {
                 $affectedRows += $this->aTypology->save($con);
             }
             $this->setTypology($this->aTypology);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = CustomerPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = CustomerPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += CustomerPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 private function edit(Offer $model)
 {
     if (isset($_POST['restore'])) {
         if ($model->restore()) {
             Yii::app()->user->setFlash('offer-restored', 'Offer is restored!');
         }
     }
     if (isset($_POST['delete'])) {
         $model->deactivate();
     }
     if ($model->off_status == Offer::STATUS_DELETED) {
         // status becomes read-only. until restored
         unset($_POST['Offer']['off_status']);
     }
     if (isset($_POST['Offer']) && $_POST['Offer']) {
         $model->attributes = $_POST['Offer'];
         if (isset($_POST['client']) && $_POST['client']) {
             $model->setClients($_POST['client']);
         }
         if ($model->save()) {
             if ($_POST['clientStatus']) {
                 foreach ($model->clients as $client) {
                     $client->cli_salestatus = $_POST['clientStatus'];
                     $client->save();
                 }
             }
             Yii::app()->user->setFlash('offer-success', 'Offer is saved!');
             $this->redirect(['update', 'id' => $model->off_id, 'popup' => $this->popupMode, 'callback' => isset($_GET['callback']) ? $_GET['callback'] : ""]);
         }
     }
     if (isset($_GET['callback']) && $_GET['callback']) {
         $callback = new PopupCallback($_GET['callback']);
         $callback->run([], isset($_POST['close']));
     } else {
         if (isset($_POST['close'])) {
             echo '<script type="text/javascript">window.close()</script>';
             Yii::app()->end();
         }
     }
     $this->render('edit', array('model' => $model));
 }
Esempio n. 7
0
 /**
  * @before _secure, _vendor
  */
 public function createOffer()
 {
     $this->seo(array("title" => "Create Offer", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     if (RequestMethods::post("action") == "saveOffer") {
         $offer = new Offer(array("user_id" => $this->user->id, "organization_id" => $this->organization->id, "property" => "package", "property_id" => RequestMethods::post("package_id"), "percent" => RequestMethods::post("percent"), "start" => RequestMethods::post("start"), "end" => RequestMethods::post("end")));
         $offer->save();
         $view->set("message", "Offer Created Successfully");
     }
     $packages = Package::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     $view->set("packages", $packages);
 }