Beispiel #1
0
 /**
  * @before _secure, _vendor
  */
 public function index()
 {
     $this->seo(array("title" => "Schedule Your Appointments", "view" => $this->getLayoutView()));
     $this->getLayoutView()->set("cal", true);
     $view = $this->getActionView();
     if (RequestMethods::post("appointment_id")) {
         if (RequestMethods::post("job_id", "")) {
             $job = Job::first(array("appointment_id = ?" => RequestMethods::post("appointment_id")));
             $job->user_id = RequestMethods::post("user_id");
         } else {
             $job = new Job(array("user_id" => RequestMethods::post("user_id"), "muser_id" => RequestMethods::post("muser_id"), "puser_id" => RequestMethods::post("puser_id"), "appointment_id" => RequestMethods::post("appointment_id"), "location_id" => RequestMethods::post("location_id"), "centre_id" => RequestMethods::post("centre_id"), "organization_id" => RequestMethods::post("organization_id")));
         }
         $job->save();
         $view->set("message", "Runner Assigned Successfully");
     }
     if (RequestMethods::post("action") == "capacity") {
         foreach (RequestMethods::post("slot") as $key => $value) {
             $slot = Slot::first(array("organization_id = ?" => $this->member->organization_id, "day = ?" => $key));
             if (isset($slot)) {
                 $slot->start = $value["start"];
                 $slot->day = $key;
                 $slot->end = $value["end"];
                 $slot->capacity = $value["hlimit"];
             } else {
                 $slot = new Slot(array("user_id" => $this->user->id, "organization_id" => $this->member->organization_id, "day" => $key, "start" => $value["start"], "end" => $value["end"], "capacity" => $value["hlimit"]));
             }
             $slot->save();
         }
         $view->set("message", "Slots Saved Successfully");
     }
     $runners = Member::all(array("organization_id = ?" => $this->member->organization_id, "designation = ?" => "runner"), array("user_id", "id"));
     $view->set("runners", $runners);
     $view->set("day", array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"));
     $view->set("slots", Slot::all(array("organization_id = ?" => $this->member->organization_id), array("start", "end", "capacity", "day")));
 }
 /**
  * @param $configdepart
  * @return bool
  */
 private function saveFlights(Configdepart $configdepart)
 {
     // Combien de flights à créer
     $nbFlights = ceil($configdepart->nbjoueurs / $configdepart->slotbyflight) + $configdepart->startergap;
     // Met a jour Configdepart->slotcount : nombre de places disponibes créees
     $configdepart->slotcount = $nbFlights * $configdepart->slotbyflight;
     $configdepart->save();
     // Supprimer les Flight de cette config
     $configdepart->flights()->delete();
     // Boucle tous les flight à créer
     for ($i = 1; $i <= $nbFlights; $i++) {
         $addMinutes = ($i - 1) * $configdepart->interval;
         $newheure = Carbon::createFromFormat('H:i', $configdepart->startheure)->addMinutes($addMinutes);
         // New Flight
         $flight = new Flight();
         $flight->configdepart_id = $configdepart->id;
         $flight->num = $i;
         $flight->heure = $newheure;
         $flight->save();
         // Cree les slots
         for ($slotnum = 1; $slotnum <= $configdepart->slotbyflight; $slotnum++) {
             $slot = new Slot();
             $slot->flight_id = $flight->id;
             $slot->num = $slotnum;
             $slot->entree_id = 0;
             $slot->save();
         }
     }
     return true;
 }
Beispiel #3
0
 function addSlot(Slot $slot)
 {
     if ($this->isSlotsAvailable()) {
         $this->total += $slot->getPeriod()->i;
         $slot->setTime(new \DateTime($this->timeIndex->format('H:i')));
         $this->slots[] = $slot;
         $this->timeIndex = $this->timeIndex->add($slot->getPeriod());
     }
     return $this;
 }
Beispiel #4
0
 /**
  * 
  * Le joueur de l'environnement rejoind la partie /!\ SI PAS DEJA FAIT
  * ou créer un invité
  * @return Slot
  */
 public function rejoindre()
 {
     Env::requiert('partie');
     Env::requiert('jeu');
     if (!joueur()) {
         Joueur::connecterInvite();
     }
     // Refus de rejoindre si la partie n'est plus en préparation et n'est pas une room non plus.
     if ($this->etat != PARTIE::PREPARATION && !jeu()->isRoom()) {
         throw new Exception('Trop tard pour rejoindre cette partie. (code etat partie : ' . $this->etat . ')');
     }
     $slot = $this->hasJoueur(joueur());
     if (!is_null($slot)) {
         return $slot;
     }
     $s = new Slot();
     $s->partie_id = $this->getID();
     $s->joueur_id = joueur()->getID();
     $s->position = count($this->slots) + 1;
     $s->save();
     $this->slots[] = $s;
     return $s;
 }
Beispiel #5
0
 public static function slots($user)
 {
     $slots = \Slot::all(["user_id = ?" => $user->id]);
     $result = [];
     foreach ($slots as $s) {
         if (array_key_exists($s->day, $result)) {
             $d = $result[$s->day][0];
             $arr = time($d->start) < time($s->start) ? [$d, $s] : [$s, $d];
             $result[$s->day] = $arr;
         } else {
             $result[$s->day] = [$s];
         }
     }
     return $result;
 }
Beispiel #6
0
 /**
  * Convert a slot to another type. The object passed on will no longer be valid.
  * 
  * @param object Slot $slot
  * @param string $type
  * @return object Slot
  * @access public
  * @since 1/4/08
  */
 public function convertSlotToType(Slot $slot, $type)
 {
     if (!isset($this->slotTypes[$type])) {
         throw new Exception("Unknown SlotType, '{$type}'. Should be one of (" . implode(", ", array_keys($this->slotTypes)) . ").");
     }
     $shortname = $slot->getShortname();
     $dbc = Services::getService("DatabaseManager");
     try {
         // Add a row to the slot table
         $query = new InsertQuery();
         $query->setTable('segue_slot');
         $query->addValue('shortname', $shortname);
         if ($slot->getSiteId()) {
             $query->addValue('site_id', $slot->getSiteId()->getIdString());
         }
         if ($slot->isAlias()) {
             $query->addValue('alias_target', $slot->getAliasTarget()->getShortname());
         }
         $query->addValue('type', $type);
         $query->addValue('location_category', $slot->getLocationCategory());
         if (!$slot->usesDefaultMediaQuota()) {
             $query->addValue('media_quota', $slot->getMediaQuota());
         }
         $dbc->query($query, IMPORTER_CONNECTION);
     } catch (DuplicateKeyDatabaseException $e) {
         // Update row to the slot table
         $query = new UpdateQuery();
         $query->setTable('segue_slot');
         $query->addWhereEqual('shortname', $shortname);
         $query->addValue('type', $type);
         $dbc->query($query, IMPORTER_CONNECTION);
     }
     // Clear our cache
     unset($this->slots[$shortname]);
     $slot = $this->getSlotByShortname($shortname);
     return $slot;
 }
 /**
  * Add a slot to a users array for an agent.
  * 
  * @param Agent $agent
  * @param Slot $slot
  * @return int
  */
 protected function addSlotForAgent(Agent $agent, Slot $slot)
 {
     $agentIdString = $agent->getId()->getIdString();
     $email = $this->getAgentEmail($agent);
     // Don't include people without email addresses
     if (empty($email)) {
         return 0;
     }
     $this->slots[$slot->getShortname()]['users'][$email] = array('name' => $agent->getDisplayName(), 'email' => $email);
     ksort($this->slots[$slot->getShortname()]['users']);
     return 1;
 }
Beispiel #8
0
 function UpdateSlotsPorts($template, $status)
 {
     //Update slots
     $template->DeleteSlots();
     for ($i = 1; $i <= $template->ChassisSlots; $i++) {
         $slot = new Slot();
         $slot->TemplateID = $template->TemplateID;
         $slot->Position = $i;
         $slot->BackSide = False;
         $slot->X = isset($_POST["XF" . $i]) ? $_POST["XF" . $i] : 0;
         $slot->Y = isset($_POST["YF" . $i]) ? $_POST["YF" . $i] : 0;
         $slot->W = isset($_POST["WF" . $i]) ? $_POST["WF" . $i] : 0;
         $slot->H = isset($_POST["HF" . $i]) ? $_POST["HF" . $i] : 0;
         $status = $slot->CreateSlot() ? $status : __("Error updating front slots");
     }
     for ($i = 1; $i <= $template->RearChassisSlots; $i++) {
         $slot = new Slot();
         $slot->TemplateID = $template->TemplateID;
         $slot->Position = $i;
         $slot->BackSide = True;
         $slot->X = isset($_POST["XR" . $i]) ? $_POST["XR" . $i] : 0;
         $slot->Y = isset($_POST["YR" . $i]) ? $_POST["YR" . $i] : 0;
         $slot->W = isset($_POST["WR" . $i]) ? $_POST["WR" . $i] : 0;
         $slot->H = isset($_POST["HR" . $i]) ? $_POST["HR" . $i] : 0;
         $status = $slot->CreateSlot() ? $status : __("Error updating rear slots");
     }
     //update template ports
     $template->DeletePorts();
     for ($i = 1; $i <= $template->NumPorts; $i++) {
         $tport = new TemplatePorts();
         $tport->TemplateID = $template->TemplateID;
         $tport->PortNumber = $i;
         $tport->Label = isset($_POST["label" . $i]) ? $_POST["label" . $i] : "";
         $tport->MediaID = isset($_POST["mt" . $i]) && $_POST["mt" . $i] > 0 ? $_POST["mt" . $i] : 0;
         $tport->ColorID = isset($_POST["cc" . $i]) && $_POST["cc" . $i] > 0 ? $_POST["cc" . $i] : 0;
         $tport->PortNotes = isset($_POST["portnotes" . $i]) ? $_POST["portnotes" . $i] : "";
         $status = $tport->CreatePort() ? $status : __("Error updating template ports");
     }
     $template->DeletePowerPorts();
     //update template power connections
     for ($i = 1; $i <= $template->PSCount; $i++) {
         $tport = new TemplatePowerPorts();
         $tport->TemplateID = $template->TemplateID;
         $tport->PortNumber = $i;
         $tport->Label = isset($_POST["powerlabel" . $i]) ? $_POST["powerlabel" . $i] : "";
         $tport->PortNotes = isset($_POST["powerportnotes" . $i]) ? $_POST["powerportnotes" . $i] : "";
         $status = $tport->CreatePort() ? $status : __("Error updating template power connections");
     }
     return $status;
 }
 public function all_departments()
 {
     $store_id = Request::segment(2);
     $this->store = Store::find($store_id);
     if (!$this->store) {
         if (Request::format() == 'html') {
             return View::make('empty_store');
         } else {
             $response_array = array('success' => 'false', 'error_code' => '404', 'error' => 'Store not Found');
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     }
     $time = date("Y-m-d H:i:s");
     $slot = Slot::where('store_id', $store_id)->where('start_time', '>', $time)->where('is_available', 1)->orderBy('start_time')->first();
     if ($slot) {
         $next_slot_start = date("D, jS M, H a", strtotime($slot->start_time));
         $next_slot_end = date("h a", strtotime($slot->end_time));
         $next_slot = $next_slot_start . " - " . $next_slot_end;
     } else {
         $next_slot = "No Slots available";
     }
     $store_data = $this->store->toArray();
     $this->store_id = $this->store->id;
     $this->departments = Department::where('store_id', $this->store_id)->orderBy('name')->get();
     $departments_data = array();
     foreach ($this->departments as $department) {
         $department_data = $department->toArray();
         $department_data['products'] = array();
         $products = Product::where('department_id', $department->id)->where('store_id', $store_id)->limit(8)->orderBy('total_sale', 'desc')->get();
         foreach ($products as $product) {
             $department_product = $product->toArray();
             array_push($department_data['products'], $department_product);
         }
         array_push($departments_data, $department_data);
     }
     $response_array['store'] = $store_data;
     $response_array['store']['next_delivery_slot'] = $next_slot;
     $response_array['store']['departments'] = $departments_data;
     if (Request::format() == 'html') {
         Session::put('store_id', $store_id);
         return View::make('store')->with('data', $response_array)->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores', $this->stores)->with('cart_id', $this->cart_id);
     } else {
         $response_array['success'] = 'true';
         $response_code = 200;
         $response = Response::json($response_array, $response_code);
         return $response;
     }
 }
Beispiel #10
0
 /**
  * Print out a slot
  * 
  * @param object $slot
  * @return object Component
  * @access public
  * @since 12/4/07
  */
 public function getSlotComponent(Slot $slot)
 {
     $harmoni = Harmoni::instance();
     ob_start();
     print "\n\t<tr>";
     print "\n\t\t<td>";
     if ($slot->siteExists()) {
         print "\n\t\t\t<a href='";
         print $harmoni->request->quickURL('ui1', 'view', array('site' => $slot->getShortname()));
         print "' target='_blank'>" . $slot->getShortname() . "</a>";
     } else {
         print $slot->getShortname();
     }
     print "</td>";
     print "\n\t\t<td>" . $slot->getType() . "</td>";
     print "\n\t\t<td>" . $slot->getLocationCategory() . "</td>";
     // Media Quota
     print "\n\t\t<td>";
     if ($slot->usesDefaultMediaQuota()) {
         $quota = SlotAbstract::getDefaultMediaQuota()->asString();
         print "<a href='#' title='{$quota}' onclick='alert(\"{$quota}\"); return false;'>";
         print _("Default");
         print "</a>";
     } else {
         print $slot->getMediaQuota()->asString();
     }
     print "</td>";
     print "\n\t\t<td style='text-align: center'>" . ($slot->siteExists() ? "yes" : '') . "</td>";
     print "\n\t\t<td>";
     $owners = $slot->getOwners();
     $ownerStrings = array();
     $agentMgr = Services::getService('Agent');
     foreach ($owners as $ownerId) {
         $ownerStrings[] = $agentMgr->getAgent($ownerId)->getDisplayName();
     }
     print implode("; ", $ownerStrings);
     print "</td>";
     $harmoni->request->passthrough('starting_number');
     $harmoni->request->startNamespace("slots");
     print "\n\t\t<td style='white-space: nowrap;'>";
     print "\n\t\t\t<a href='";
     print $harmoni->request->quickURL('slots', 'edit', array('name' => $slot->getShortname()));
     print "'>" . _("edit") . "</a>";
     if (!$slot->siteExists()) {
         $harmoni->request->startNamespace(null);
         print "\n\t\t\t| <a href='";
         print $harmoni->request->quickURL('dataport', 'import', array('site' => $slot->getShortname()));
         print "'>" . _("import") . "</a>";
         $harmoni->request->endNamespace();
         print "\n\t\t\t| <a href='";
         print $harmoni->request->quickURL('slots', 'delete', array('name' => $slot->getShortname()));
         print "' onclick=\"";
         print "return confirm('" . _('Are you sure you want to delete this placeholder?') . "');";
         print "\">" . _("delete") . "</a>";
     } else {
         $harmoni->request->startNamespace(null);
         print "\n\t\t\t| <a href='";
         print $harmoni->request->quickURL('dataport', 'export', array('node' => $slot->getSiteId()->getIdString()));
         print "'>" . _("export") . "</a>";
         $harmoni->request->endNamespace();
     }
     print "\n\t\t</td>";
     $harmoni->request->endNamespace();
     $harmoni->request->forget('starting_number');
     print "\n\t</tr>";
     return ob_get_clean();
 }
Beispiel #11
0
                $m->CreateManufacturer();
            }
        }
    }
}
$mList = $m->getSubscriptionList();
foreach ($mList as $man) {
    curl_setopt($c, CURLOPT_URL, 'https://repository.opendcim.org/api/template/bymanufacturer/' . $man->GlobalID);
    curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'GET');
    $result = curl_exec($c);
    $jr = json_decode($result);
    if (@$jr->errorcode == 200) {
        if (is_array($jr->templates)) {
            foreach ($jr->templates as $tem) {
                $tm = new Manufacturer();
                $cs = new Slot();
                $tp = new TemplatePorts();
                $tpp = new TemplatePowerPorts();
                foreach ($t as $prop => $val) {
                    @($t->{$prop} = $tem->{$prop});
                }
                $m->GlobalID = $t->ManufacturerID;
                $m->getManufacturerByGlobalID();
                $t->ManufacturerID = $m->ManufacturerID;
                // Snag the images
                if ($t->FrontPictureFile != "") {
                    $tmpname = explode(".", basename($t->FrontPictureFile), 2);
                    $frontname = $picturedir . $tmpname[1];
                    grab_image($t->FrontPictureFile, $frontname);
                    $t->FrontPictureFile = $tmpname[1];
                }
 /**
  * Adds a site to the buffer.
  *
  * @param object site $site The site to add.
  * @param integer $indent The indent level of the object
  */
 function addSite(&$site)
 {
     // Add flags for when to add permissions rows
     $site->spiderDownLockedFlag();
     $siteElement =& $this->_document->createElement('site');
     $this->_document->appendChild($siteElement);
     // site id and type
     $siteElement->setAttribute('owner', slot::getOwner($site->getField('name')));
     $siteElement->setAttribute('type', $site->getField('type'));
     // Media quota
     $slot = new Slot($site->getField('name'));
     $quota = $slot->getField('quota');
     if ($quota) {
         $siteElement->setAttribute('mediaQuota', $quota);
     }
     $this->addCommonProporties($site, $siteElement);
     // use the slot-name for backwards-compatability
     $siteElement->setAttribute('id', $site->getField('name'));
     // header
     $header =& $this->_document->createElement('header');
     $siteElement->appendChild($header);
     $header->appendChild($this->_document->createTextNode(htmlspecialchars($site->getField('header'))));
     // footer
     $footer =& $this->_document->createElement('footer');
     $siteElement->appendChild($footer);
     $footer->appendChild($this->_document->createTextNode(htmlspecialchars($site->getField('footer'))));
     // Theme
     $this->addTheme($site, $siteElement);
     // Media
     $this->addMedia($site, $siteElement);
     // sections
     foreach ($site->sections as $key => $val) {
         if ($site->sections[$key]->getField('type') == 'link') {
             $this->addSectionNavLink($site->sections[$key], $siteElement);
         } else {
             if ($site->sections[$key]->getField('type') == 'heading') {
                 $this->addHeading($site->sections[$key], $siteElement);
             } else {
                 if ($site->sections[$key]->getField('type') == 'divider') {
                     $this->addDivider($site->sections[$key], $siteElement);
                 } else {
                     $this->addSection($site->sections[$key], $siteElement);
                 }
             }
         }
     }
 }
Beispiel #13
0
 /**
  * @before _secure, _doctor
  */
 public function appointments()
 {
     $this->seo(array("title" => "My Appointments", "view" => $this->getLayoutView()));
     $this->getLayoutView()->set("cal", true);
     $view = $this->getActionView();
     $appointments = array();
     $page = RequestMethods::get("page", 1);
     $limit = RequestMethods::get("limit", 10);
     $count = Appointment::count(array("user_id" => $this->user->id));
     $as = Appointment::all(array("user_id =?" => $this->user->id, "live = ?" => 1), array("id", "service_id", "start", "end", "patient_id"), "start", "asc", $limit, $page);
     foreach ($as as $a) {
         $service = Service::first(array("id = ?" => $a->service_id), array("property", "property_id", "organization_id", "charge"));
         $organization = Organization::first(array("id = ?" => $service->organization_id), array("id", "name"));
         $model = ucfirst($service->property);
         $item = $model::first(array("id = ?" => $service->property_id), array("title"));
         $patient = User::first(array("id = ?" => $a->patient_id), array("name"));
         array_push($appointments, array("item" => $item->title, "organization_id" => $organization->id, "organization_name" => $organization->name, "patient" => $patient->name, "start" => $a->start, "end" => $a->end, "id" => $a->id, "charge" => $service->charge));
     }
     $organization = Registry::get("session")->get("organization");
     if (RequestMethods::post("action") == "capacity") {
         \Slot::saveRecord($this->user, $organization);
         $view->set("message", "Slots Saved Successfully");
     }
     $view->set("appointments", $appointments);
     $days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
     $view->set("days", $days);
     $view->set("slots", Shared\Services\Doctor::slots($this->user));
 }
Beispiel #14
0
 /**
  * Print info about a Slot
  * 
  * @param object Slot $slot
  * @return void
  * @access private
  * @since 3/13/08
  */
 private function printSlotInfo(Slot $slot)
 {
     $harmoni = Harmoni::instance();
     if ($slot->siteExists()) {
         $asset = $slot->getSiteAsset();
         try {
             $authZ = Services::getService('AuthZ');
             $idMgr = Services::getService('Id');
             if (!$authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.view'), $slot->getSiteId())) {
                 print "\n<div class='site_info'>";
                 print "\n\t<div class='site_description'>";
                 print _("A site has been created for this placeholder, but you do not have authorization to view it.");
                 print "</div>";
                 print "\n</div>";
                 return;
             }
         } catch (UnknownIdException $e) {
         }
         $viewUrl = SiteDispatcher::quickURL('view', 'html', array('site' => $slot->getShortname()));
         print "\n<div class='site_info'>";
         print "\n\t<div class='site_title'>";
         print "\n\t\t<a href='" . $viewUrl . "' target='_blank'>";
         print "\n\t\t\t<strong>" . HtmlString::getSafeHtml($asset->getDisplayName()) . "</strong>";
         print "\n\t\t</a>";
         print "\n\t</div>";
         $description = HtmlString::withValue($asset->getDescription());
         $description->trim(25);
         print "\n\t<div class='site_description'>" . $description->asString() . "</div>";
         print "\n</div>";
     }
     print "\n\t<div class='slotname'>";
     print $slot->getShortname();
     print "\n\t</div>";
 }
Beispiel #15
0
 /**
  * Make this slot an alias of another slot. 
  * 
  * @param object Slot $targetSlot
  * @return void
  * @access public
  * @since 10/8/08
  */
 public function makeAlias(Slot $targetSlot)
 {
     if (!is_null($this->siteId)) {
         throw new OperationFailedException("Cannot make a slot with an existing site an Alias.");
     }
     if ($this->isAlias()) {
         throw new OperationFailedException("This slot is already an Alias.");
     }
     // Check for cycles in aliases.
     $target = $targetSlot;
     while ($target) {
         if ($this->getShortname() == $target->getShortname()) {
             throw new OperationFailedException("Cannot create loops of aliases.");
         }
         if ($target->isAlias()) {
             $target = $target->getAliasTarget();
         } else {
             $target = null;
         }
     }
     $this->aliasTarget = $targetSlot->getShortname();
     $this->recordInDB();
     $query = new UpdateQuery();
     $query->setTable('segue_slot');
     $query->addWhereEqual('shortname', $this->getShortname());
     $query->addValue('alias_target', $targetSlot->getShortname());
     $dbc = Services::getService('DBHandler');
     try {
         $dbc->query($query, IMPORTER_CONNECTION);
     } catch (QueryDatabaseException $e) {
         $this->aliasTarget = null;
         throw new OperationFailedException("Unknown target placeholder, '" . $targetSlot->getShortname() . "'.");
     }
 }
Beispiel #16
0
 /**
  * Answer a link to move/copy a site to a new slot.
  * 
  * @param object Slot $slot
  * @return string
  * @access public
  * @since 10/10/08
  */
 public function getSiteMoveCopyLink(Slot $slot)
 {
     $this->addHeadJavascript();
     $harmoni = Harmoni::instance();
     $harmoni->request->startNamespace("selection");
     ob_start();
     print "<a ";
     print " style='cursor: pointer;'";
     print " class='Selection_MoveCopy_Link' ";
     print " onclick=\"MoveCopyPanel.run('" . $slot->getShortname() . "', 'Slot', [], this); return false;\"";
     print " title=\"" . _("Paste from your Selection") . "\"";
     print ">" . _('Paste');
     print "</a>";
     $harmoni->request->endNamespace();
     return ob_get_clean();
 }
 public function delete_slot()
 {
     $id = Input::get('id');
     $slot = Slot::find($id);
     $store_id = $slot->store_id;
     $slot->delete();
     $message = "Successfully deleted the a delivery slot";
     $type = "danger";
     return Redirect::to('/admin/store/' . $store_id . '/slots')->with('type', $type)->with('message', $message);
 }
Beispiel #18
0
 /**
  * AuthZ
  * 
  * @return boolean
  * @access public
  * @since 3/14/08
  */
 protected function canChangeSlotStatus(Slot $slot)
 {
     if (!$slot->siteExists()) {
         return $slot->isUserOwner();
     }
     // get siteRoot node and check that
     $idMgr = Services::getService('Id');
     $azMgr = Services::getService('AuthZ');
     // Since view AZs cascade up, just check at the node.
     return $azMgr->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.modify'), $slot->getSiteId());
 }
 public function checkout_step3()
 {
     // Processing Cart
     $cart_id = $this->cart_id;
     if (!$cart_id) {
         $cart_id = Input::get('cart_id');
     }
     $address_id = Input::get('address_id');
     $payment_id = Input::get('payment_id');
     $cart_products = DB::table('cart_products')->where('cart_id', $cart_id)->leftJoin('products', 'cart_products.product_id', '=', 'products.id')->leftJoin('users', 'cart_products.added_by', '=', 'users.id')->select('products.*', 'cart_products.quantity as cart_quantity', 'users.first_name as added_by')->orderBy('store_id')->get();
     $cart_users = DB::table('cart_users')->leftJoin('users', 'cart_users.user_id', '=', 'users.id')->select('users.*')->get();
     $response_array['cart'] = Cart::find($cart_id)->toArray();
     $response_array['cart']['total_amount'] = 0;
     $response_array['cart']['total_quantity'] = 0;
     $response_array['cart']['users'] = array();
     $response_array['cart']['stores'] = array();
     $store_id = 0;
     if ($cart_products) {
         $response_array['cart']['is_minimum_reached'] = 1;
         foreach ($cart_products as $cart_product) {
             if ($store_id != $cart_product->store_id) {
                 $store_id = $cart_product->store_id;
                 // Retriving Store
                 $store = Store::find($store_id)->toArray();
                 // Retriving Delivery Slot
                 $time = date("Y-m-d H:i:s");
                 $slot = Slot::where('store_id', $store_id)->where('start_time', '>', $time)->where('is_available', 1)->orderBy('start_time')->first();
                 if ($slot) {
                     $next_slot_start = date("D, jS M, H a", strtotime($slot->start_time));
                     $next_slot_end = date("h a", strtotime($slot->end_time));
                     $next_slot = $next_slot_start . " - " . $next_slot_end;
                 } else {
                     $next_slot = "No Slots available";
                 }
                 $store['slot'] = $next_slot;
                 $store['count'] = 1;
                 $store['sub_total'] = 0;
                 $response_array['cart']['stores'][$store_id] = $store;
                 $response_array['cart']['stores'][$store_id]['products'] = array();
             } else {
                 $response_array['cart']['stores'][$store_id]['count'] += 1;
             }
             $product = json_decode(json_encode($cart_product), true);
             $product['sub_total'] = $product['cart_quantity'] * $product['price'];
             $response_array['cart']['stores'][$store_id]['sub_total'] += $product['sub_total'];
             $response_array['cart']['total_amount'] += $product['sub_total'];
             $response_array['cart']['total_quantity']++;
             array_push($response_array['cart']['stores'][$store_id]['products'], $product);
         }
     }
     if ($cart_users) {
         foreach ($cart_users as $cart_user) {
             $product = json_decode(json_encode($cart_user), true);
             array_push($response_array['cart']['users'], $cart_user);
         }
     }
     foreach ($response_array['cart']['stores'] as $st) {
         if ($st['sub_total'] < $st['minimum_order_amount']) {
             $response_array['cart']['is_minimum_reached'] = 0;
         }
     }
     if (isset($response_array['cart']['is_minimum_reached']) && $response_array['cart']['is_minimum_reached'] == 1) {
         $order = new Order();
         $order->user_id = $this->user_id;
         $order->date = date("Y-m-d H:i:s");
         $order->total_products = $response_array['cart']['total_quantity'];
         $order->total_amount = $response_array['cart']['total_amount'];
         $order->payment_id = $payment_id;
         $order->address_id = $address_id;
         $payment = Payment::find($payment_id);
         $order->payment_customer_id = $payment->customer_id;
         $address = UserAddress::find($address_id);
         $order->address = $address->address . " " . $address->zipcode;
         $order->status = "Initiated";
         $order->save();
         foreach ($cart_products as $cart_product) {
             $order_product = new OrderProduct();
             $order_product->order_id = $order->id;
             $product = Product::find($cart_product->id);
             $product->total_sale += $cart_product->cart_quantity;
             $product->save();
             $order_product->price = $cart_product->price;
             $order_product->quantity = $cart_product->cart_quantity;
             $order_product->fulfilment_status = "Pending";
             $order_product->type = "Product";
             $order_product->parent_id = 0;
             $order_product->product_name = $product->name;
             $order_product->product_image_url = $product->image_url;
             $order_product->product_quantity = $product->quantity;
             $order_product->product_unit = $product->unit;
             $order_product->store_id = $product->store_id;
             $order_product->save();
         }
         // removing products from cart
         CartProduct::where('cart_id', $cart_id)->delete();
         // Order Placement Mail
         $user = User::find($this->user_id);
         Mail::send('emails.order_success', array('user' => $user, 'order' => $order), function ($message) use($user) {
             $message->to($user->email, $user->first_name)->subject('Thanks for placing the order!');
         });
         // Order Placement Mail to Admin
         $admin_email = Config::get('app.admin_email');
         Mail::send('emails.admin_order_success', array('user' => $user, 'order' => $order), function ($message) use($admin_email) {
             $message->to($admin_email, "Admin")->subject('New Order!');
         });
     } else {
         $message = "Minimum order amount not reached";
         if (Request::format() == 'html') {
             return View::make('checkout_step3')->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores1', $this->stores)->with('message', $message);
         } else {
             $response_array = array('success' => false, 'error_code' => 411, 'error' => $message);
             $response_code = 200;
             $response = Response::json($response_array, $response_code);
             return $response;
         }
     }
     if (Request::format() == 'html') {
         return View::make('checkout_step3')->with('store', $this->store)->with('departments', $this->departments)->with('zipcode', $this->zipcode)->with('city', $this->city)->with('stores1', $this->stores)->with('message', 'Thanks for placing your Order!!');
     } else {
         $response_array = array('success' => true);
         $response_code = 200;
         $response = Response::json($response_array, $response_code);
         return $response;
     }
 }
 /**
  * Answer the baseURL to use for a slot
  * 
  * @param object Slot $slot
  * @return string
  * @access public
  * @since 8/7/08
  * @static
  */
 public static function getBaseUrlForSlot(Slot $slot)
 {
     if (isset(self::$locationCategoryUrls[$slot->getLocationCategory()])) {
         return self::$locationCategoryUrls[$slot->getLocationCategory()];
     }
     return MYURL;
 }
Beispiel #21
0
 function GetChildDevicePicture($parentDetails, $rear = false)
 {
     /*
      * The following section will make a few assumptions
      * - All dimensions will be given back as a percentage of the whole for scalability
      * -- Labels will be the exception to that, we're just going to assign them values
      * - Child devices will only have one face, front
      * -- This makes the pictures on the templates easier to manage
      * --- Children of an HTRAY or VTRAY will be treated as any other device with a front
      *		and a rear image.  This makes this just stupidly complicated but has to be done
      * -- Child devices defined with rear slots will have the rear slots ignored
      * --- This logic needs to be applied to the functions that figure power usage and weight
      *		so we don't end up with phantom sources
      * - Child devices shouldn't need to conform to the 1.75:19 ratio we use for devices 
      *		directly in a cabinet they will target the slot that they are inside
      */
     $resp = "";
     $templ = new DeviceTemplate();
     $templ->TemplateID = $this->TemplateID;
     $templ->GetTemplateByID();
     $parentDev = $parentDetails->parentDev;
     $parentTempl = $parentDetails->parentTempl;
     // API path correction
     $path = "";
     if (preg_match('/api\\//', str_replace(DIRECTORY_SEPARATOR, '/', getcwd()))) {
         $path = "../../";
     }
     // We'll only consider checking a rear image on a child if it is sitting on a shelf
     if (($parentTempl->Model == 'HTRAY' || $parentTempl->Model == 'VTRAY') && $rear) {
         $picturefile = "pictures/{$templ->RearPictureFile}";
     } else {
         $picturefile = "pictures/{$templ->FrontPictureFile}";
     }
     if (!file_exists($path . $picturefile)) {
         $picturefile = "pictures/P_ERROR.png";
     }
     @(list($width, $height) = getimagesize($path . $picturefile));
     // Make sure there is an image! DOH! If either is 0 then use a text box
     $width = intval($width);
     $height = intval($height);
     $noimage = false;
     if ($width == 0 || $height == 0) {
         $noimage = true;
         if ($parentTempl->Model == 'HTRAY') {
             $height = $parentDetails->targetWidth;
             $width = $parentDetails->targetHeight;
         } elseif ($parentTempl->Model == 'VTRAY') {
             $width = $parentDetails->targetWidth;
             $height = $parentDetails->targetHeight;
         }
     }
     // In the event of read error this will rotate a horizontal text label
     $hor_blade = $width == "" || $height == "" ? true : $width > $height;
     // We only need these numbers in the event that we have a nested device
     // and need to scale the coordinates based off the original image size
     $kidsHavingKids = new stdClass();
     $kidsHavingKids->Height = $height ? $height : 1;
     $kidsHavingKids->Width = $width ? $width : 1;
     $slot = new Slot();
     $slotOK = false;
     //get slot from DB
     $slot->TemplateID = $parentDev->TemplateID;
     $slot->Position = $this->Position;
     $slot->BackSide = $this->BackSide;
     if ($parentTempl->Model == 'HTRAY' || $parentTempl->Model == 'VTRAY' || $slot->GetSlot()) {
         // If we're dealing with a shelf mimic what GetSlot() would have done for our fake slot
         if ($parentTempl->Model == 'HTRAY' || $parentTempl->Model == 'VTRAY') {
             $imageratio = $hor_blade || !$hor_blade && $parentTempl->Model == 'HTRAY' ? $width / $height : $height / $width;
             // If we don't have an image this will make the text box fit correctly, hopefully
             if ($noimage) {
                 $imageratio = $parentTempl->Model == 'HTRAY' ? $height / $width : $width / $height;
             }
             $slot->W = $parentTempl->Model == 'HTRAY' ? $parentDetails->targetWidth / $parentDev->ChassisSlots : $parentDetails->targetWidth;
             $slot->H = $parentTempl->Model == 'HTRAY' ? $parentDetails->targetHeight : $parentDetails->targetHeight / $parentDev->ChassisSlots;
             $slot->X = $parentTempl->Model == 'HTRAY' ? $rear ? ($parentDev->ChassisSlots - $this->Position - $this->Height + 1) * $slot->W : ($slot->Position - 1) * $slot->W : 0;
             $slot->Y = $parentTempl->Model == 'HTRAY' ? 0 : $parentDetails->targetHeight - $parentDetails->targetHeight / $parentDev->ChassisSlots * ($this->Position + $this->Height - 1);
             // Enlarge the slot if needed
             $slot->H = $parentTempl->Model == 'HTRAY' ? $parentDetails->targetHeight : $parentDetails->targetHeight / $parentDev->ChassisSlots * $this->Height;
             $slot->W = $parentTempl->Model == 'HTRAY' ? $parentDetails->targetWidth / $parentDev->ChassisSlots * $this->Height : $slot->H * $imageratio;
             // To center the devices in the slot we first needed to know the width figured just above
             $slot->X = $parentTempl->Model == 'VTRAY' ? ($parentDetails->targetWidth - $slot->W) / 2 : $slot->X;
             // This covers the event that an image scaled properly will be too wide for the slot.
             // Recalculate all the things!  Shelves are stupid.
             if ($parentTempl->Model == 'VTRAY' && $slot->W > $parentDetails->targetWidth) {
                 $originalH = $slot->H;
                 $slot->W = $parentDetails->targetWidth;
                 $slot->H = $slot->W / $imageratio;
                 $slot->X = 0;
                 $slot->Y = $originalH - $slot->H;
             }
             if ($parentTempl->Model == 'HTRAY' && $slot->W > $slot->H * $imageratio) {
                 $originalW = $slot->W;
                 $originalX = $slot->X;
                 $slot->W = $slot->H * $imageratio;
                 $slot->X = $rear ? $originalX + ($originalW - $slot->W) : $slot->X;
             } elseif ($parentTempl->Model == 'HTRAY' && $slot->H > $slot->W * $this->Height / $imageratio && !$noimage) {
                 $originalH = $slot->H;
                 $slot->H = $hor_blade ? $slot->W * $imageratio : $slot->W / $imageratio;
                 $slot->Y = $originalH - $slot->H;
             }
             // Reset the zoome on the parent to 1 just for trays
             $parentDetails->zoomX = 1;
             $parentDetails->zoomY = 1;
         }
         // Check for slot orientation before we possibly modify it via height
         $hor_slot = $slot->W > $slot->H;
         // We dealt with the slot sizing above for trays this will bypass the next bit
         if ($parentTempl->Model == 'HTRAY' || $parentTempl->Model == 'VTRAY') {
             $slotOK = true;
             $this->Height = 0;
         }
         // This will prevent the freak occurance of a child device with a 0 height
         if ($this->Height >= 1) {
             // If height==1 then just accept the defined slot as is
             if ($this->Height > 1) {
                 //get last slot
                 $lslot = new Slot();
                 $lslot->TemplateID = $slot->TemplateID;
                 $lslot->Position = $slot->Position + $this->Height - 1;
                 // If the height extends past the defined slots then just get the last slot
                 if ($lslot->Position > ($slot->BackSide ? $parentDev->RearChassisSlots : $parentDev->ChassisSlots)) {
                     $lslot->Position = $slot->BackSide ? $parentDev->RearChassisSlots : $parentDev->ChassisSlots;
                 }
                 $lslot->BackSide = $slot->BackSide;
                 if ($lslot->GetSlot()) {
                     //calculate total size
                     $xmin = min($slot->X, $lslot->X);
                     $ymin = min($slot->Y, $lslot->Y);
                     $xmax = max($slot->X + $slot->W, $lslot->X + $lslot->W);
                     $ymax = max($slot->Y + $slot->H, $lslot->Y + $lslot->H);
                     //put new size in $slot
                     $slot->X = $xmin;
                     $slot->Y = $ymin;
                     $slot->W = $xmax - $xmin;
                     $slot->H = $ymax - $ymin;
                 } else {
                     // Last slot isn't defined so just error out
                     break;
                 }
             }
             $slotOK = true;
         }
     }
     if ($slotOK) {
         // Determine if the element needs to be rotated or not
         // This only evaluates if we have a horizontal image in a vertical slot
         $rotar = !$hor_slot && $hor_blade ? "rotar_d" : "";
         // Scale the slot to fit the forced aspect ratio
         $zoomX = $parentDetails->zoomX;
         $zoomY = $parentDetails->zoomY;
         $slot->X = $slot->X * $zoomX;
         $slot->Y = $slot->Y * $zoomY;
         $slot->W = $slot->W * $zoomX;
         $slot->H = $slot->H * $zoomY;
         if ($rotar) {
             $left = $slot->X - abs($slot->W - $slot->H) / 2;
             $top = $slot->Y + abs($slot->W - $slot->H) / 2;
             $height = $slot->W;
             $width = $slot->H;
         } else {
             $left = $slot->X;
             $top = $slot->Y;
             $height = $slot->H;
             $width = $slot->W;
         }
         $left = intval(round($left));
         $top = intval(round($top));
         $height = intval(round($height));
         $width = intval(round($width));
         // If they have rights to the device then make the picture clickable
         $clickable = $this->Rights != "None" ? "\t\t\t<a href=\"devices.php?DeviceID={$this->DeviceID}\">\n" : "";
         $clickableend = $this->Rights != "None" ? "\t\t\t</a>\n" : "";
         // Add in flags for missing ownership
         // Device pictures are set on the template so always assume template has been set
         $flags = $this->Owner == 0 ? '(O)&nbsp;' : '';
         $flags = $this->TemplateID == 0 ? $flags . '(T)&nbsp;' : $flags;
         $flags = $flags != '' ? '<span class="hlight">' . $flags . '</span>' : '';
         $label = "";
         $resp .= "\t\t<div class=\"dept{$this->Owner} {$rotar}\" style=\"left: " . number_format(round($left / $parentDetails->targetWidth * 100, 2), 2, '.', '') . "%; top: " . number_format(round($top / $parentDetails->targetHeight * 100, 2), 2, '.', '') . "%; width: " . number_format(round($width / $parentDetails->targetWidth * 100, 2), 2, '.', '') . "%; height:" . number_format(round($height / $parentDetails->targetHeight * 100, 2), 2, '.', '') . "%;\">\n{$clickable}";
         //			if(($templ->FrontPictureFile!="" && !$rear) || ($templ->RearPictureFile!="" && $rear)){
         if ($picturefile != 'pictures/') {
             // IMAGE
             // this rotate should only happen for a horizontal slot with a vertical image
             $rotateimage = $hor_slot && !$hor_blade ? " class=\"rotar_d rlt\"  style=\"height: " . number_format(round($width / $height * 100, 2), 2, '.', '') . "%; left: 100%; width: " . number_format(round($height / $width * 100, 2), 2, '.', '') . "%; top: 0; position: absolute;\"" : "";
             $resp .= "\t\t\t\t<img data-deviceid={$this->DeviceID} src=\"{$picturefile}\"{$rotateimage} alt=\"{$this->Label}\">\n";
             // LABEL FOR IMAGE
             if ($hor_slot || $rotar && !$hor_slot) {
                 $label = "\t\t\t<div class=\"label\" style=\"line-height:" . $height . "px; height:" . $height . "px;" . ($height * 0.8 < 13 ? " font-size: " . intval($height * 0.8) . "px;" : "") . "\">";
             } else {
                 // This is a vertical slot with a vertical picture so we have to rotate the label
                 $label = "\t\t\t<div class=\"rotar_d rlt label\" style=\"top: calc(" . $height . "px * 0.05); left: " . $width . "px; width: calc(" . $height . "px * 0.9); line-height:" . $width . "px; height:" . $width . "px;" . ($width * 0.8 < 13 ? " font-size: " . intval($width * 0.8) . "px; " : "") . "\">";
             }
             $label .= "<div>{$flags}{$this->Label}" . ($rear ? " (" . __("Rear") . ")" : "") . "</div></div>\n";
         } else {
             //LABEL for child device without image - Always show
             $resp .= "\t\t\t\t<div class=\"label noimage\" data-deviceid={$this->DeviceID} style='height: " . $height . "px; line-height:" . $height . "px; " . ($height * 0.8 < 13 ? " font-size: " . intval($height * 0.8) . "px;" : "") . "'>";
             $resp .= "<div>{$flags}{$this->Label}" . ($rear ? " (" . __("Rear") . ")" : "") . "</div></div>\n";
         }
         $resp .= $clickableend . $label;
         // If the label on a nested chassis device proves to be a pita remove the label
         // above and uncomment the following if
         // if($this->ChassisSlots<4){$resp.=$label;}
         if ($this->ChassisSlots > 0) {
             $kidsHavingKids->targetWidth = $width;
             $kidsHavingKids->targetHeight = $height;
             $kidsHavingKids->zoomX = $width / $kidsHavingKids->Width;
             $kidsHavingKids->zoomY = $height / $kidsHavingKids->Height;
             $kidsHavingKids->parentDev = $this;
             $kidsHavingKids->parentTempl = $templ;
             //multichassis
             $childList = $this->GetDeviceChildren();
             foreach ($childList as $tmpDev) {
                 if (!$tmpDev->BackSide && !$rear || $tmpDev->BackSide && $rear) {
                     $resp .= $tmpDev->GetChildDevicePicture($kidsHavingKids, $rear);
                 }
             }
         }
         $resp .= "\t\t</div>\n";
     }
     return $resp;
 }
Beispiel #22
0
 function GetFirstSlot()
 {
     $this->MakeSafe();
     $sql = "SELECT * FROM fac_Slots WHERE TemplateID={$this->TemplateID} ORDER BY BackSide,Position;";
     if ($row = $this->query($sql)->fetch()) {
         foreach (Slot::RowToObject($row) as $prop => $value) {
             $this->{$prop} = $value;
         }
         return true;
     } else {
         return false;
     }
 }
Beispiel #23
0
            $response['errorcode'] = 200;
            $response['powerport'] = $tp;
        }
    }
    echoResponse(200, $response);
});
//
//	URL:	/api/v1/devicetemplate/:templateid/slot/:slotnum
//	Method:	PUT
//	Params:
//		Required: templateid, slotnum
//		Optional: everything else
//	Returns: record as created
//
$app->put('/devicetemplate/:templateid/slot/:slotnum', function ($templateid, $slotnum) use($app, $person) {
    $s = new Slot();
    foreach ($app->request->put() as $prop => $val) {
        $s->{$prop} = $val;
    }
    // This should be in the commit data but if we get a smartass saying it's in the URL
    $s->TemplateID = $templateid;
    $s->Position = $slotnum;
    if (!$person->WriteAccess) {
        $response['error'] = true;
        $response['errorcode'] = 403;
        $response['message'] = __("Unauthorized");
    } else {
        if (!$s->CreateSlot()) {
            $response['error'] = true;
            $response['errorcode'] = 404;
            $response['message'] = __("Device template slot creation failed");
Beispiel #24
0
 /**
  * Create the new site with this template at the slot specified.
  * 
  * @param object Slot $slot
  * @param optional string $displayName
  * @param optional string $description
  * @return object SiteNavBlockSiteComponent
  * @access public
  * @since 6/11/08
  */
 public function createSite(Slot $slot, $displayName = 'Untitled', $description = '')
 {
     $director = SiteDispatcher::getSiteDirector();
     $doc = new Harmoni_DOMDocument();
     $doc->load($this->_path . "/site.xml");
     // Validate the document contents
     $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd");
     $mediaDir = $this->_path . "/media";
     if (!file_exists($mediaDir)) {
         $mediaDir = null;
     }
     // @todo Strip out any history.
     $importer = new StripHistoryImportSiteVisitor($doc, $mediaDir, $director);
     $importer->disableCommentImport();
     $site = $importer->importAtSlot($slot->getShortname());
     try {
         // Replace #SITE_NAME# and #SITE_DESCRIPTION# placeholders
         $site->acceptVisitor(new Segue_Templates_ReplacePlaceholderVisitor($displayName, $description));
     } catch (Exception $e) {
         $director->deleteSiteComponent($site);
         $slot->deleteSiteId();
         throw $e;
     }
     return $site;
 }