Exemplo n.º 1
0
 /**
  * See stats of a keyword
  * @before _secure, memberLayout
  */
 public function stats($keyword_id)
 {
     $keyword = \Keyword::first(array("id = ?" => $keyword_id, "serp = ?" => true));
     $this->_authority($keyword);
     $rank = Registry::get("MongoDB")->rank;
     $r = $rank->findOne(['keyword_id' => (int) $keyword->id, 'created' => date('Y-m-d')]);
     if ($keyword->live && !$r) {
         try {
             Shared\Service\Serp::record(array($keyword));
         } catch (\Exception $e) {
         }
     }
     $end_date = RequestMethods::get("enddate", date("Y-m-d"));
     $start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
     $this->seo(array("title" => "Serp | Stats", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date);
     $i = 0;
     $obj = array();
     while ($start_time < $end_time) {
         $start_time = strtotime($start_date . " +{$i} day");
         $date = date('Y-m-d', $start_time);
         $record = $rank->findOne(array('created' => $date, 'keyword_id' => (int) $keyword->id));
         if (isset($record)) {
             $position = $record['position'];
         } else {
             $position = 0;
         }
         $obj[] = array('y' => $date, 'a' => $position);
         ++$i;
     }
     $view->set("keyword", $keyword)->set("label", "Rank")->set("data", ArrayMethods::toObject($obj));
 }
Exemplo n.º 2
0
 public function packages()
 {
     $view = $this->getActionView();
     $states = State::all();
     $view->set('states', $states);
     $source = RequestMethods::get('source');
     $source_state = State::first(array('id = ?' => $source));
     $dest = RequestMethods::get('dest');
     $dest_state = State::first(array('id = ?' => $dest));
     $month = RequestMethods::get('month');
     $year = RequestMethods::get('year');
     $page = RequestMethods::get('page', 1);
     $limit = 9;
     if (RequestMethods::get('source')) {
         $count = Package::count(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year));
         $total_pages = $count / 9 + 1;
         for ($i = 1; $i <= $total_pages; $i++) {
             $pages[$i] = $i;
         }
         $packages = Package::all(array('source Like ?' => $source, 'destination Like ?' => $dest, 'month = ?' => $month, 'year = ?' => $year, 'live = ?' => 1), array("*"), null, null, $limit, $page);
         $view->set('n', 'http://planyourtours.io/travels/packages?source=' . $source . '&dest=' . $dest . '&type=Group&month=' . $month . '&year=' . $year . '&page=')->set('source', $source_state)->set('dest', $dest_state)->set('month', $month)->set('year', $year);
     } else {
         $count = Package::count();
         $total_pages = $count / 9 + 1;
         for ($i = 1; $i <= $total_pages; $i++) {
             $pages[$i] = $i;
         }
         $packages = Package::all(array('live = ?' => 1), array("*"), null, null, $limit, $page);
         $view->set('n', 'http://planyourtours.io/travels/packages?&page=');
     }
     if (!empty($packages)) {
         $view->set('packages', $packages)->set('pages', $pages);
     }
 }
Exemplo n.º 3
0
 public static function page($opts = array())
 {
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $count = $opts["model"]::count($opts["where"]);
     return array("limit" => $limit, "page" => $page, "count" => $count);
 }
Exemplo n.º 4
0
 public function index()
 {
     $this->getLayoutView()->set("seo", Framework\Registry::get("seo"));
     $view = $this->getActionView();
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $items = Campaign::all(array("live = ?" => true), array("id", "live", "image", "title", "description"), "created", "desc", $limit, $page);
     $count = Campaign::count(array("live = ?" => true));
     $view->set("items", $items)->set("count", $count)->set("limit", $limit)->set("page", $page);
 }
Exemplo n.º 5
0
 /**
  * @before _secure, _admin
  */
 public function all()
 {
     $this->seo(array("title" => "Manage FakeReferer URLs", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $page = RequestMethods::get("page", 1);
     $limit = RequestMethods::get("limit", 10);
     $count = \Referer::count(array());
     $referers = \Referer::all(array());
     $view->set(array("referers" => $referers, "page" => $page, "limit" => $limit, "count" => $count));
 }
Exemplo n.º 6
0
 public function area($city_id)
 {
     $this->noview();
     $data = array();
     $keyword = RequestMethods::get("keyword");
     $areas = Area::all(array("city_id = ?" => $city_id, "name LIKE ?" => "%{$keyword}%"), array("name", "id"));
     foreach ($areas as $a) {
         array_push($data, array("id" => $a->id, "name" => $a->name));
     }
     echo json_encode($data);
 }
Exemplo n.º 7
0
 /**
  * @before _secure, _admin
  */
 public function all()
 {
     $this->seo(array("title" => "View Users Stats", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $page = RequestMethods::get("page", 1);
     $limit = RequestMethods::get("limit", 10);
     $orderBy = RequestMethods::get("orderBy", "created");
     $users = \User::all(array(), array("*"), $orderBy, "desc", $limit, $page);
     $total = \User::count();
     $view->set(array("count" => $total, "results" => $users, "limit" => $limit, "page" => (int) $page));
 }
Exemplo n.º 8
0
 /**
  * @before _secure, changeLayout, _admin
  */
 public function participants()
 {
     $this->seo(array("title" => "Game Participants", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $participants = Participant::all(array(), array("*"), "created", "desc", $limit, $page);
     $count = Participant::count();
     $view->set("participants", $participants);
     $view->set("count", $count);
     $view->set("limit", $limit);
     $view->set("page", $page);
 }
Exemplo n.º 9
0
 /**
  * @before _secure, memberLayout
  */
 public function index()
 {
     if (RequestMethods::get("download")) {
         $this->noview();
         $file = APP_PATH . '/public/detector.txt';
         header("Content-Type: application/octet-stream; ");
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . filesize($file) . ";");
         header("Content-disposition: attachment; filename=" . 'trafficmonitor.php');
         readfile($file);
         return;
     }
     $this->seo(array("title" => "Dashboard", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $websites = Website::all(array("user_id = ?" => $this->user->id));
     $view->set(array("actions" => $this->actions, "trigs" => $this->triggers, "websites" => $websites));
 }
Exemplo n.º 10
0
 /**
  * @before _secure, _school
  */
 public function manage()
 {
     $this->setSEO(array("title" => "Create Exam | School"));
     $view = $this->getActionView();
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $exams = Exam::all(array("organization_id = ?" => $this->organization->id), array("*"), "created", "desc", $limit, $page);
     $count = Exam::count(array("organization_id = ?" => $this->organization->id));
     $grades = Grade::all(array("organization_id = ?" => $this->organization->id), array("id", "title"));
     $setGrades = array();
     foreach ($grades as $g) {
         $setGrades["{$g->id}"] = $g->title;
     }
     $view->set("limit", $limit);
     $view->set("page", $page);
     $view->set("count", $count);
     $view->set("exams", $exams);
     $view->set("grades", $setGrades);
 }
Exemplo n.º 11
0
 public function getBooks()
 {
     $this->isApiNavigation = true;
     $arrayWhere = array();
     $arrayGet = array();
     $arrayGet['isbn'] = \Framework\RequestMethods::get('isbn', true, null);
     $arrayGet['title'] = \Framework\RequestMethods::get('title', true, null);
     $arrayGet['author.last_name'] = \Framework\RequestMethods::get('author', true, null);
     //$arrayGet['author.first_name'] = \Framework\RequestMethods::get('author', true, null);
     foreach ($arrayGet as $k => $v) {
         if (!is_null($v)) {
             $arrayWhere[$k] = array('%' . $v . '%', 'LIKE');
         }
     }
     $rating = \Framework\RequestMethods::get('rating', true, null);
     if (!is_null($rating) && is_numeric($rating)) {
         $arrayWhere['rating'] = array($rating, '>=');
     }
     $year = \Framework\RequestMethods::get('year', true, null);
     if (!is_null($rating) && is_numeric($rating)) {
         $arrayWhere['year'] = $year;
     }
     $start_date = strtotime(\Framework\RequestMethods::get('start_date', true, false));
     $end_date = strtotime(\Framework\RequestMethods::get('end_date', true, false));
     if ($start_date) {
         $arrayWhere['book.created'] = array('FROM_UNIXTIME(' . $start_date . ')', '>=', true);
     }
     if ($end_date) {
         $arrayWhere['book.created'] = array('FROM_UNIXTIME(' . $end_date . ')', '<=', true);
     }
     $books = Book::getAllForApi($arrayWhere);
     if (!is_null($books)) {
         $this->actionView->set('books', $books);
     } else {
         \Framework\Registry::get('httpRequest')->setResponseCode(\Framework\HttpRequest::HTTP_RESPONSE_NO_CONTENT);
     }
 }
Exemplo n.º 12
0
 /**
  * Find the Performance of Affiliates|Advertisers of an organization
  * @param  object $org  \Organization
  * @param  string $type Type of user
  * @return [type]       [description]
  */
 public static function perf($org, $type, $opts = [])
 {
     $start = $opts['start'] ?? RequestMethods::get('start', date('Y-m-d', strtotime("-5 day")));
     $end = $opts['end'] ?? RequestMethods::get('end', date('Y-m-d', strtotime("-1 day")));
     switch ($type) {
         case 'publisher':
             $perfFields = $opts['fields'] ?? ['clicks', 'impressions', 'conversions', 'revenue', 'created'];
             $meta = $opts['meta'] ?? false;
             if ($meta) {
                 $perfFields[] = 'meta';
             }
             $publishers = $opts['publishers'] ?? $org->users($type);
             $pubPerf = Perf::all(['user_id' => ['$in' => $publishers], 'created' => Db::dateQuery($start, $end)], $perfFields, 'created', 'asc');
             $pubPerf = Perf::objectArr($pubPerf, $perfFields);
             return $pubPerf;
         case 'advertiser':
             $advertisers = $opts['advertisers'] ?? $org->users($type);
             $fields = $opts['fields'] ?? ['revenue', 'created'];
             $advertPerf = Perf::all(['user_id' => ['$in' => $advertisers], 'created' => Db::dateQuery($start, $end)], $fields, 'created', 'asc');
             $advertPerf = Perf::objectArr($advertPerf, $fields);
             return $advertPerf;
     }
     return [];
 }
Exemplo n.º 13
0
 /**
  * @before _secure, memberLayout
  */
 public function stats($keyword_id)
 {
     $keyword = \Keyword::first(array("id = ?" => $keyword_id, "serp = ?" => false), array("link", "user_id", "id"));
     $this->_authority($keyword);
     Shared\Service\Social::record($keyword);
     $end_date = RequestMethods::get("enddate", date("Y-m-d"));
     $start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
     $social_media = RequestMethods::get("media", "facebook");
     $this->seo(array("title" => "Serp | Stats", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $socials = Registry::get("MongoDB")->socials;
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date);
     $obj = array();
     $records = $socials->find(array('created' => array('$gte' => new MongoDate($start_time), '$lte' => new MongoDate($end_time)), 'social_media' => (string) $social_media, 'keyword_id' => (int) $keyword->id));
     foreach ($records as $r) {
         $position = $r['count'];
         $media = array();
         $media['count_type'] = $r['count_type'];
         $media['social_media'] = $r['social_media'];
         $obj[] = array('y' => date('Y-m-d', $r['created']->sec), 'a' => $position);
     }
     $view->set("keyword", $keyword)->set("label", $media['count_type'])->set("social", array("type" => $media['count_type'], "media" => $media['social_media']))->set("data", ArrayMethods::toObject($obj));
 }
Exemplo n.º 14
0
 /**
  * @before _secure, _admin
  */
 public function dataAnalysis()
 {
     $this->seo(array("title" => "Data Analysis", "keywords" => "admin", "description" => "admin", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     if (RequestMethods::get("action") == "dataAnalysis") {
         $startdate = RequestMethods::get("startdate");
         $enddate = RequestMethods::get("enddate");
         $model = ucfirst(RequestMethods::get("model"));
         $diff = date_diff(date_create($startdate), date_create($enddate));
         for ($i = 0; $i < $diff->format("%a"); $i++) {
             $date = date('Y-m-d', strtotime($startdate . " +{$i} day"));
             $count = $model::count(array("created LIKE ?" => "%{$date}%"));
             $obj[] = array('y' => $date, 'a' => $count);
         }
         $view->set("data", \Framework\ArrayMethods::toObject($obj));
     }
 }
Exemplo n.º 15
0
 /**
  * @before _secure, _vendor
  */
 public function manage($param = null)
 {
     $this->seo(array("title" => "Manage Runner Profile", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $page = RequestMethods::get("page", 1);
     $limit = RequestMethods::get("limit", 10);
     $where = array("organization_id = ?" => $this->member->organization_id, "designation = ?" => "runner", "live = ?" => 1);
     $runners = Member::all($where, array("DISTINCT user_id"), "created", "desc", $limit, $page);
     $count = Member::count($where);
     $view->set("runners", $runners);
     $view->set("page", $page);
     $view->set("count", $count);
     $view->set("limit", $limit);
 }
Exemplo n.º 16
0
 /**
  * @before _secure, memberLayout, _check
  */
 public function sitemap()
 {
     $this->seo(array("title" => "Webmasters | Crawl Errors", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $response = $this->_setAccessToken();
     if ($response["url"]) {
         $view->set("url", $response["url"]);
         return;
     }
     $websites = $this->_getWebsites($response["gClient"]);
     $url = RequestMethods::get("website", $websites[0]->getSiteUrl());
     $result = $this->_getSiteMaps($response["gClient"], $url);
     if (is_string($result)) {
         $result = null;
     }
     $view->set("current", $url);
     $view->set("websites", $websites);
     $view->set("response", $result);
 }
Exemplo n.º 17
0
 public function forgotpassword()
 {
     $this->seo(array("title" => "Register", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     if (RequestMethods::post("action") == "change") {
         $token = RequestMethods::post("token");
         $id = base64_decode($token);
         $user = User::first(array("id = ?" => $id));
         if (RequestMethods::post("password") == RequestMethods::post("cpassword")) {
             $user->password = sha1(RequestMethods::post("password"));
             $user->save();
             $this->session($user);
             $this->redirect("/member");
         } else {
             $view->set("message", 'Password Does not match');
         }
     }
     if (RequestMethods::get("action") == "reset") {
         $token = RequestMethods::get("token");
         $id = base64_decode($token);
         $exist = User::first(array("id = ?" => $id), array("id"));
         if ($exist) {
             $view->set("token", $token);
         } else {
             $view->set("message", 'Something Went Wrong please contact admin');
         }
     }
 }
Exemplo n.º 18
0
 public function location()
 {
     $this->JSONview();
     $view = $this->getActionView();
     $input = RequestMethods::get("query");
     $result = file_get_contents("https://maps.googleapis.com/maps/api/place/autocomplete/json?key=AIzaSyA7Gyp0hkc5frFBy5KLHxU2gu_QPmTnGXQ&input=" . $input);
     $view->set("result", $result);
 }
Exemplo n.º 19
0
 /**
  * @before _secure, memberLayout
  */
 public function logs($website_id)
 {
     $this->seo(array("title" => "Logs for your website", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $this->getLayoutView()->set("logs", true);
     $mongo = Registry::get("MongoDB");
     $website = $mongo->website;
     $record = $website->findOne(array("website_id" => (int) $website_id));
     if (!$record || $record['user_id'] != $this->user->id) {
         $this->redirect("/404");
     }
     $this->_clearLogs($website_id);
     $logs = $mongo->logs;
     $where = array('website_id' => (int) $website_id);
     $page = RequestMethods::get("page", 1);
     $limit = RequestMethods::get("limit", 30);
     $count = $logs->count($where);
     $cursor = $logs->find($where, array('_id' => false));
     $cursor->skip($limit * ($page - 1));
     $cursor->limit($limit);
     $cursor->sort(array('created' => -1));
     $results = array();
     foreach ($cursor as $c) {
         $c = ArrayMethods::toObject($c);
         $results[] = $c;
     }
     $view->set("logs", $results)->set("page", $page)->set("limit", $limit)->set("actions", $this->actions)->set("ts", $this->triggers)->set("count", $count);
 }
Exemplo n.º 20
0
 /**
  * @before _secure, _vendor, _admin
  */
 public function payments()
 {
     $this->seo(array("title" => "Vendor Profile", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $where["organization_id = ?"] = $this->organization->id;
     $period = RequestMethods::get("period", "total");
     switch ($period) {
         case 'year':
             $year = strftime("%Y-%m-%d", strtotime('-1 year'));
             $where["created > ?"] = $year;
             break;
         case 'week':
             $week = strftime("%Y-%m-%d", strtotime('-1 year'));
             $where["created > ?"] = $week;
             break;
         case 'day':
             $day = strftime("%Y-%m-%d", strtotime('-1 day'));
             $where["created > ?"] = $day;
             break;
     }
     $centres = Centre::all(array("organization_id = ?" => $this->organization->id), array("id", "location_id"));
     $revenue = 0;
     $cash = 0;
     $online = 0;
     $appointments = Appointment::all($where);
     foreach ($appointments as $a) {
         $order = Order::first(array("id = ?" => $a->order_id), array("amount"));
         $revenue += $order->amount;
         switch ($order->mode) {
             case 'cash':
                 $cash += $order->amount;
                 break;
             default:
                 $online += $order->amount;
                 break;
         }
     }
     if (RequestMethods::get("action") == "invoice") {
         $this->paymentsInvoice($this->organization, $appointments, $revenue, $cash, $online, "show");
     }
     $view->set("appointments", $appointments);
     $view->set("period", $period);
     $view->set("revenue", $revenue);
     $view->set("cash", $cash);
     $view->set("online", $online);
     $view->set("centres", $centres);
 }
Exemplo n.º 21
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));
 }
Exemplo n.º 22
0
 /**
  * @before _secure, _admin
  */
 public function groupMembers($group_id)
 {
     $group = Group::first(array("id = ?" => $group_id));
     if (!$group || $group->name == "All") {
         $this->redirect("/admin");
     }
     $this->seo(array("title" => "Manage Group Members", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $count = RequestMethods::get("count", 10);
     $group->users = json_decode($group->users);
     if ($count < count($group->users)) {
         $count = count($group->users) + 1;
     }
     $total = array();
     for ($i = 0; $i < $count; ++$i) {
         $total[] = $i;
     }
     if (RequestMethods::post("action") == "addMembers") {
         unset($_POST["action"]);
         $members = ArrayMethods::reArray($_POST);
         $members = json_encode($members);
         $group->users = $members;
         $group->save();
         $view->set("success", "Members were added for the group: {$group->name}");
     }
     $view->set("group", $group);
     $view->set("count", $total);
 }
Exemplo n.º 23
0
 /**
  * @before _secure, _vendor
  */
 public function reports()
 {
     $this->seo(array("title" => "Test Report", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $centre_id = RequestMethods::get("centre_id", $this->member->centre_id);
     $appointments = Appointment::all(array("centre_id = ?" => $centre_id), array("id", "patient_id", "user_id", "service_id", "start"));
     $view->set("appointments", $appointments);
     if (RequestMethods::post("action") == "report") {
         $appt_id = RequestMethods::post("appointment_id");
         if (!array_key_exists($appt_id, $appointments)) {
             $view->set("message", "Invalid request!!");
             return;
         }
         $appt = $appointments[$appt_id];
         $job = Job::first(array("appointment_id = ?" => $appt->id));
         if (!$job) {
             $view->set("message", "Invalid Request!!");
             return;
         }
         // find emails
         $user = User::first(array("id = ?" => $appt->user_id), array("email"));
         $patient = User::first(array("id = ?" => $appt->patient_id), array("email"));
         if (!$user->email && !$patient->email) {
             $view->set("message", "No email to send message to");
             return;
         } elseif (!$patient->email) {
             $emails = $user->email;
         } else {
             $emails = array($user->email, $patient->email);
             $emails = array_unique($emails);
         }
         // upload file
         $file = $this->_upload('file', "files", array("extensions" => "pdf"));
         if (!$file) {
             $view->set("message", "File upload failed!!");
             return;
         }
         $file_path = APP_PATH . '/public/assets/uploads/files/' . $file;
         $name = $this->organization->name;
         Shared\Services\Mail::notify(array("emails" => $emails, "delivery" => "sendgrid", "template" => "sendReport", "lab" => $name, "apptime" => \Framework\StringMethods::datetime_to_text($appt->start), "subject" => RequestMethods::post("report_detail"), "attachment" => $file_path));
         unlink($file_path);
         $job->live = 1;
         $job->save();
         $view->set("message", "Sent Successfully");
     }
 }
Exemplo n.º 24
0
 public function popularPackages()
 {
     $this->seo(array("title" => "Popular Packages", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $organizations = Organization::all(array("live = ?" => true), array("id", "name"));
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $packages = Package::all(array("live = ?" => 1), array("title", "organization_id", "charge", "id"), "created", "desc", $limit, $page);
     $total = (int) Package::count(array("live = ?" => 1));
     $results = array();
     foreach ($packages as $p) {
         $data = array("title" => $p->title, "lab" => $organizations[$p->organization_id]->name, "lab_id" => $p->organization_id, "charge" => $p->charge, "id" => $p->id);
         $results[] = ArrayMethods::toObject($data);
     }
     $view->set("packages", $results)->set("total", $total);
 }
Exemplo n.º 25
0
 public function search()
 {
     $view = $this->getActionView();
     $states = State::all();
     $view->set('states', $states);
     $source = RequestMethods::get('source');
     $source_state = State::first(array('id = ?' => $source));
     $dest = RequestMethods::get('dest');
     $dest_state = State::first(array('id = ?' => $dest));
     $people = RequestMethods::get('people');
     $start = RequestMethods::get('start');
     $end = RequestMethods::get('end');
     $drivers = CabDriver::all(array('state = ?' => RequestMethods::get('source')));
     $startdate = strtotime($start);
     $enddate = strtotime($end);
     $today = strtotime(date('Y-m-d'));
     $i = 0;
     foreach ($drivers as $driver) {
         $bookings = CabBooking::all(array('driver_id = ?' => $driver->id));
         $flag = 0;
         foreach ($bookings as $booking) {
             $booking_startdate = strtotime($booking->startdate);
             $booking_enddate = strtotime($booking->enddate);
             if ($startdate < $enddate) {
                 $flag = 1;
                 break;
             }
             if ($startdate < $today) {
                 $flag = 1;
                 break;
             }
             if ($startdate >= $booking_startdate && $enddate <= $booking_enddate || $startdate <= $booking_startdate && $enddate >= $booking_enddate || $startdate <= $booking_startdate && $enddate <= $booking_enddate && $enddate >= $booking_startdate || $startdate >= $booking_startdate && $startdate <= $booking_enddate && $enddate >= $booking_enddate) {
                 $flag = 1;
                 break;
             }
         }
         if ($driver->seater < RequestMethods::get('people')) {
             $flag = 1;
         }
         if ($flag == 0) {
             $available_drivers[$i] = $driver->id;
             $i++;
         }
     }
     $view->set('source', $source_state)->set('dest', $dest_state)->set('start', $start)->set('end', $end)->set('people', $people);
     if (!empty($available_drivers)) {
         $view->set('drivers', $available_drivers);
         foreach ($available_drivers as $driver) {
             $type_e = CabDriver::first(array('id = ?' => $driver));
             if ($type_e->type == 'economy') {
                 $view->set('type1', '');
                 break;
             }
         }
         foreach ($available_drivers as $driver) {
             $type_e = CabDriver::first(array('id = ?' => $driver));
             if ($type_e->type == 'premium') {
                 $view->set('type2', '');
                 break;
             }
         }
     }
     if ($this->user) {
         if (RequestMethods::post('car')) {
             foreach ($available_drivers as $driver) {
                 $cab = CabDriver::first(array('id = ?' => $driver, 'car_name = ?' => RequestMethods::post('car')));
                 break;
             }
             if ($cab) {
                 $booking = new CabBooking(array('user_id' => $this->user->id, 'driver_id' => $cab->id, 'startdate' => $start, 'enddate' => $end, 'startplace' => $source, 'endplace' => $dest));
                 if ($booking->validate()) {
                     $booking->save();
                     header('/cab/confirmation/' . $booking->id);
                 }
             } else {
                 echo "<script> alert('Something went wrong') </script>";
             }
         }
     } else {
         echo "<script> alert('login first') </script>";
     }
 }
Exemplo n.º 26
0
 /**
  * @before _secure, _admin
  */
 public function transactions()
 {
     $this->seo(array("title" => "Transactions", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $page = RequestMethods::get("page", $page);
     $limit = RequestMethods::get("limit", $limit);
     $transactions = Transaction::all(array(), array("user_id", "property", "property_id", "payment_id", "amount", "created"), "created", "desc", $limit, $page);
     $view->set("transactions", $transactions);
     $view->set("page", $page);
     $view->set("limit", $limit);
     $view->set("count", Transaction::count());
 }
Exemplo n.º 27
0
 /**
  * Manages all school registered
  * @before _secure, _school, _admin
  */
 public function all()
 {
     $this->setSEO(array("title" => "All Schools"));
     $view = $this->getActionView();
     $limit = RequestMethods::get("limit", 10);
     $page = RequestMethods::get("page", 1);
     $organizations = Organization::all(array(), array("name", "user_id", "created"), "created", "desc", $limit, $page);
     $view->set("organizations", $organizations);
 }
Exemplo n.º 28
0
 /**
  * @before _secure, memberLayout
  */
 public function stats()
 {
     $this->seo(array("title" => "Ping | Stats", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $url = RequestMethods::get("link");
     $ping = Registry::get("MongoDB")->ping;
     $search = array('user_id' => (int) $this->user->id, 'url' => $url);
     $record = $ping->findOne($search);
     if (!$record) {
         $this->redirect("/404");
     }
     $end_date = RequestMethods::get("enddate", date("Y-m-d"));
     $start_date = RequestMethods::get("startdate", date("Y-m-d", strtotime($end_date . "-7 day")));
     $start_time = strtotime($start_date);
     $end_time = strtotime($end_date);
     $ping_stats = Registry::get("MongoDB")->ping_stats;
     $records = $ping_stats->find(array('ping_id' => $record['_id'], 'created' => array('$gte' => new \MongoDate($start_time), '$lte' => new \MongoDate($end_time))));
     $obj = array();
     foreach ($records as $r) {
         $obj[] = array('y' => date('Y-m-d H:i:s', $r['created']->sec), 'a' => $r['latency']);
     }
     $view->set('ping', ArrayMethods::toObject($record))->set('label', 'Latency')->set('data', ArrayMethods::toObject($obj));
 }
Exemplo n.º 29
0
 /**
  * @before _secure
  */
 public function ping()
 {
     $this->JSONview();
     $view = $this->getActionView();
     $url = RequestMethods::get("link");
     if (!$url) {
         $this->redirect("/404");
     }
     $count = 0;
     $stats = Registry::get("MongoDB")->ping_stats;
     $ping = Registry::get("MongoDB")->ping;
     $record = $ping->findOne(array('url' => $url, 'user_id' => (int) $this->user->id));
     if (!$record) {
         $this->redirect("/404");
     }
     $count = $stats->count(array('ping_id' => $record['_id']));
     $cursor = $stats->find(array('ping_id' => $record['_id']));
     $cursor->sort(['created' => -1]);
     $cursor->limit(1);
     foreach ($cursor as $c) {
         $live = $c['latency'];
     }
     $count += $count;
     $view->set("count", $count)->set("status", $live === false ? "down" : "up")->set("success", true);
 }
Exemplo n.º 30
0
 public function success()
 {
     $this->seo(array("title" => "Thank You", "view" => $this->getLayoutView()));
     $view = $this->getActionView();
     $configuration = Registry::get("configuration");
     $payment_request_id = RequestMethods::get("payment_request_id");
     if ($payment_request_id) {
         $instamojo = Instamojo::first(array("payment_request_id = ?" => $payment_request_id));
         if ($instamojo) {
             $imojo = $configuration->parse("configuration/payment");
             $curl = new Curl();
             $curl->setHeader('X-Api-Key', $imojo->payment->instamojo->key);
             $curl->setHeader('X-Auth-Token', $imojo->payment->instamojo->auth);
             $curl->get('https://www.instamojo.com/api/1.1/payment-requests/' . $payment_request_id . '/');
             $payment = $curl->response;
             $instamojo->status = $payment->payment_request->status;
             $instamojo->save();
             $order = Order::first(array("id = ?" => $instamojo->purpose_id));
             $order->ref_id = $instamojo->id;
             $order->save();
             $appointments = Appointment::all(array("order_id = ?" => $order->id), array("id"));
             foreach ($appointments as $appointment) {
                 $appointment = Appointment::first(array("id = ?" => $appointment->id));
                 $appointment->live = 1;
                 $appointment->save();
             }
             $user = User::first(array("id = ?" => $instamojo->user_id));
             $point = new Point(array("user_id" => $instamojo->user_id, "property" => "appointment", "property_id" => $instamojo->purpose_id, "unit" => 0.01 * ($order->amount / 1.12)));
             $point->save();
             $this->generateinvoice($order->id, $instamojo->id);
             Shared\Services\Mail::notify(array("template" => "confirmAppointment", "subject" => "Appointment Confirmed", "appointment" => $appointment, "instamojo" => $instamojo, "point" => $point, "user" => $user, "attachment" => APP_PATH . "/public/assets/uploads/files/orders/{$order->id}.pdf"));
         }
     }
 }