Ejemplo n.º 1
0
$operator = Operator::getInstance()->GetLoggedOperator();
$show_empty = isset($_REQUEST['show_empty']) && $_REQUEST['show_empty'] == 1 ? true : false;
if (isset($_REQUEST['q'])) {
    $q = $_REQUEST['q'];
    $items_per_page = verify_param('items', "/^\\d{1,3}\$/", DEFAULT_ITEMS_PER_PAGE);
    $op_param = verify_param('operator', "/^\\d+\$/");
    // TODO should be operatorid
    $departmentidParam = verify_param('departmentid', "/^\\d+\$/");
    $localeParam = verify_param($_REQUEST['locale'], '/^[a-z]{2}$/');
    $rateParam = verify_param('rate', "/^\\w+\$/");
    $startday = verify_param('startday', "/^\\d+\$/");
    $startmonth = verify_param('startmonth', "/^\\d{2}.\\d{2}\$/");
    $endday = verify_param('endday', "/^\\d+\$/");
    $endmonth = verify_param('endmonth', "/^\\d{2}.\\d{2}\$/");
    $start = get_form_date($startday, $startmonth);
    $end = get_form_date($endday, $endmonth) + 24 * 60 * 60;
    $offlineParam = verify_param('offline', "/^\\d+\$/");
    if ($offlineParam !== null) {
        $offlineParam = $offlineParam == 1 ? 0 : 1;
    }
    if ($start > $end) {
        $errors[] = Resources::Get('search.wrong.dates');
    } else {
        $nTotal = Thread::getInstance()->GetListThreadsAdvCount($operator['operatorid'], $q, $start, $end, $op_param, $show_empty, $departmentidParam, $localeParam, $rateParam, $offlineParam);
        if ($nTotal) {
            $pagination = setup_pagination_cnt($nTotal, $items_per_page);
            $nLimit = $pagination['items'];
            $nOffset = $pagination['start'];
            $threads = Thread::getInstance()->GetListThreadsAdv($operator['operatorid'], $q, $start, $end, $op_param, $show_empty, $departmentidParam, $localeParam, $rateParam, $offlineParam, $nLimit, $nOffset);
            $tmlPage['pagination'] = $pagination;
            $tmlPage['pagination_items'] = $threads;
Ejemplo n.º 2
0
 /**
  * Extracts start and end timestamps from the interval related with the
  * request.
  *
  * @param Request $request Incoming request
  * @return array Associative array with the following keys:
  *  - "start": int, timestamp for beginning of the interval.
  *  - "end": int, timestamp for ending of the interval.
  */
 protected function extractTimeInterval(Request $request)
 {
     if ($request->query->has('startday')) {
         // The request contains info about interval.
         $start_day = $request->query->get('startday');
         $start_month = $request->query->get('startmonth');
         $end_day = $request->query->get('endday');
         $end_month = $request->query->get('endmonth');
         // Check if all necessary info is specified.
         $bad_request = !preg_match("/^\\d+\$/", $start_day) || !preg_match("/^\\d{2}.\\d{2}\$/", $start_month) || !preg_match("/^\\d+\$/", $end_day) || !preg_match("/^\\d{2}.\\d{2}\$/", $end_month);
         if ($bad_request) {
             throw new BadRequestException();
         }
         return array('start' => get_form_date($start_day, $start_month), 'end' => get_form_date($end_day, $end_month) + 24 * 60 * 60);
     }
     // The request does not contain info about interval. Use defaults.
     $curr = getdate(time());
     if ($curr['mday'] < 7) {
         // Use previous month if it is the first week of the month
         if ($curr['mon'] == 1) {
             $month = 12;
             $year = $curr['year'] - 1;
         } else {
             $month = $curr['mon'] - 1;
             $year = $curr['year'];
         }
         $start = mktime(0, 0, 0, $month, 1, $year);
         $end = mktime(0, 0, 0, $month, date('t', $start), $year) + 24 * 60 * 60;
         return array('start' => $start, 'end' => $end);
     }
     // Use the current month
     return array('start' => mktime(0, 0, 0, $curr['mon'], 1, $curr['year']), 'end' => time() + 24 * 60 * 60);
 }