Ejemplo n.º 1
0
 /**
  * Encodes the data as a JSON string to be used in JavaScript code.
  *
  * @static
  *
  * @param mixed $data
  * @param bool  $forceObject force all arrays to objects
  *
  * @return mixed
  */
 public static function encodeJson($data, $forceObject = false)
 {
     if (self::$json === null) {
         self::$json = new CJson();
     }
     return self::$json->encode($data, [], $forceObject);
 }
Ejemplo n.º 2
0
 /**
  * Output ajax response. If any error was added, 'result' is false, otherwise true.
  *
  * @return void
  */
 public function send()
 {
     $json = new CJson();
     if ($this->_result) {
         echo $json->encode(['result' => true, 'data' => $this->_data]);
     } else {
         echo $json->encode(['result' => false, 'errors' => $this->_errors]);
     }
 }
Ejemplo n.º 3
0
 public function send($pUrl, $pMethod = self::RM_GET, $pData = array())
 {
     $optArr = array('http' => array('method' => $pMethod, 'header' => 'Content-Type: text/plain;charset=utf-8'));
     $stream = \stream_context_create($optArr);
     switch ($pMethod) {
         case self::RM_PUT:
         case self::RM_POST:
             $optArr['http']['content'] = CJson::encode($pData);
             $stream = \stream_context_create($optArr);
             $res = \file_get_contents(sprintf('%s:%s/%s', self::$HOST, self::$PORT, $pUrl), null, $stream);
             break;
         case self::RM_DELETE:
         case self::RM_GET:
             if (count($pData) > 0) {
                 $res = \file_get_contents(sprintf('%s:%s/%s?%s', self::$HOST, self::$PORT, $pUrl, \http_build_query($pData)), null, $stream);
             } else {
                 $res = \file_get_contents(sprintf('%s:%s/%s', self::$HOST, self::$PORT, $pUrl), null, $stream);
             }
             break;
     }
     return $res;
 }
Ejemplo n.º 4
0
 /**
  * Creates an HTTP cookie to be sent along with an HTTP response.
  *
  * Internally, the value of a cookie is always stored as a string. If the cookie's value was provided as an array
  * or map, it's encoded into JSON and is stored as a JSON string. Boolean values are stored as "1" for `true` and
  * as "0" for `false`.
  *
  * @param  string $cookieName The cookie's name.
  * @param  mixed $value The cookie's value. This can be a string, a `bool`, an `int`, a `float`, an array, or a
  * map.
  */
 public function __construct($cookieName, $value)
 {
     assert('is_cstring($cookieName) && (is_cstring($value) || is_bool($value) || is_int($value) || ' . 'is_float($value) || is_collection($value))', vs(isset($this), get_defined_vars()));
     $this->m_name = $cookieName;
     if (is_cstring($value)) {
         $this->m_value = $value;
     } else {
         if (is_bool($value)) {
             $this->m_value = CString::fromBool10($value);
         } else {
             if (is_int($value)) {
                 $this->m_value = CString::fromInt($value);
             } else {
                 if (is_float($value)) {
                     $this->m_value = CString::fromFloat($value);
                 } else {
                     $json = new CJson($value);
                     $this->m_value = $json->encode();
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 /**
  * Convert array with export data to JSON format.
  *
  * @param array $array
  *
  * @return string
  */
 public function write(array $array)
 {
     $json = new CJson();
     return $json->encode($array);
 }
Ejemplo n.º 6
0
function imageOut(&$image, $format = null)
{
    global $page, $IMAGE_FORMAT_DEFAULT;
    if (is_null($format)) {
        $format = $IMAGE_FORMAT_DEFAULT;
    }
    ob_start();
    if (IMAGE_FORMAT_JPEG == $format) {
        imagejpeg($image);
    } else {
        imagepng($image);
    }
    $imageSource = ob_get_contents();
    ob_end_clean();
    if ($page['type'] != PAGE_TYPE_IMAGE) {
        session_start();
        $imageId = md5(strlen($imageSource));
        $_SESSION['image_id'] = array();
        $_SESSION['image_id'][$imageId] = $imageSource;
        session_write_close();
    }
    switch ($page['type']) {
        case PAGE_TYPE_IMAGE:
            echo $imageSource;
            break;
        case PAGE_TYPE_JSON:
            $json = new CJson();
            echo $json->encode(array('result' => $imageId));
            break;
        case PAGE_TYPE_TEXT:
        default:
            echo $imageId;
    }
}
Ejemplo n.º 7
0
    $mapInfo = getSelementsInfo($map, array('severity_min' => getRequest('severity_min')));
    processAreasCoordinates($map, $areas, $mapInfo);
    $allLinks = false;
}
/*
 * Draw map
 */
drawMapConnectors($im, $map, $mapInfo, $allLinks);
if (!isset($_REQUEST['noselements'])) {
    drawMapHighligts($im, $map, $mapInfo);
    drawMapSelements($im, $map, $mapInfo);
}
$expandMacros = getRequest('expand_macros', true);
drawMapLabels($im, $map, $mapInfo, $expandMacros);
drawMapLinkLabels($im, $map, $mapInfo, $expandMacros);
if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) {
    drawMapSelementsMarks($im, $map, $mapInfo);
}
show_messages();
if (getRequest('base64image')) {
    ob_start();
    imagepng($im);
    $imageSource = ob_get_contents();
    ob_end_clean();
    $json = new CJson();
    echo $json->encode(array('result' => base64_encode($imageSource)));
    imagedestroy($im);
} else {
    imageOut($im);
}
require_once dirname(__FILE__) . '/include/page_footer.php';
Ejemplo n.º 8
0
function imageOut(&$image, $format = null)
{
    global $page, $IMAGE_FORMAT_DEFAULT;
    if (is_null($format)) {
        $format = $IMAGE_FORMAT_DEFAULT;
    }
    ob_start();
    if (IMAGE_FORMAT_JPEG == $format) {
        imagejpeg($image);
    } else {
        imagepng($image);
    }
    $imageSource = ob_get_contents();
    ob_end_clean();
    if ($page['type'] != PAGE_TYPE_IMAGE) {
        $imageId = md5(strlen($imageSource));
        CSession::setValue('image_id', [$imageId => $imageSource]);
    }
    switch ($page['type']) {
        case PAGE_TYPE_IMAGE:
            echo $imageSource;
            break;
        case PAGE_TYPE_JSON:
            $json = new CJson();
            echo $json->encode(['result' => $imageId]);
            break;
        case PAGE_TYPE_TEXT:
        default:
            echo $imageId;
    }
}
Ejemplo n.º 9
0
                if ($triggers) {
                    CArrayHelper::sort($triggers, array(array('field' => 'description', 'order' => ZBX_SORT_UP)));
                    if (isset($data['limit'])) {
                        $triggers = array_slice($triggers, 0, $data['limit']);
                    }
                    foreach ($triggers as $trigger) {
                        $hostName = '';
                        if ($trigger['hosts']) {
                            $trigger['hosts'] = reset($trigger['hosts']);
                            $hostName = $trigger['hosts']['name'] . NAME_DELIMITER;
                        }
                        $result[] = array('id' => $trigger['triggerid'], 'name' => $trigger['description'], 'prefix' => $hostName);
                    }
                }
                break;
        }
        break;
    default:
        fatal_error('Wrong RPC call to JS RPC!');
}
if ($requestType == PAGE_TYPE_JSON) {
    if (isset($data['id'])) {
        echo $json->encode(array('jsonrpc' => '2.0', 'result' => $result, 'id' => $data['id']));
    }
} elseif ($requestType == PAGE_TYPE_TEXT_RETURN_JSON) {
    $json = new CJson();
    echo $json->encode(array('jsonrpc' => '2.0', 'result' => $result));
} elseif ($requestType == PAGE_TYPE_TEXT || $requestType == PAGE_TYPE_JS) {
    echo $result;
}
require_once dirname(__FILE__) . '/include/page_footer.php';
 public function actionSavePayments()
 {
     // Changes in payment block in order managment      // Не лишняя ли это функция?
     $this->_prepairJson();
     $orderId = $this->_request->getParam('order_id');
     $payment = ProjectPayments::model()->find('order_id = :ORDER_ID', array(':ORDER_ID' => $orderId));
     if (!$payment) {
         $payment = new ProjectPayments();
         $payment->order_id = $orderId;
         $payment->received = 0;
         $payment->to_receive = 0;
         $payment->to_pay = 0;
     }
     $to_receive = $this->_request->getParam('to_receive', 0);
     if ($this->_request->getParam('project_price')) {
         $payment->project_price = $this->_request->getParam('project_price');
     }
     if ($this->_request->getParam('to_receive')) {
         $payment->to_receive += (int) $this->_request->getParam('to_receive');
     }
     if (!($this->_request->getParam('work_price') === null)) {
         $payment->work_price = $this->_request->getParam('work_price');
     }
     if ($this->_request->getParam('to_pay')) {
         $paying = (int) $this->_request->getParam('to_pay');
     }
     if ($paying > 0 && $to_receive == 0 && $payment->work_price > 0 && $paying + $payment->to_pay > $payment->work_price + $payment->payed && (int) $payment->to_pay > 0) {
         echo CJson::encode(['Оплата превышает лимит']);
         Yii::app()->end();
     }
     $payment->to_pay += $paying;
     if ($payment->save()) {
         //(To User)
         $order = Zakaz::model()->findByPk($orderId);
         if ($payment->project_price > 0 && $order && $order->status == 1) {
             $order->status = 2;
             $order->save(false);
         }
         //(To Author)
         //$order = Zakaz::model()->findByPk($orderId);
         if ($paying > 0) {
             $user = User::model()->with('profile')->findByPk($order->executor);
             $manag = User::model()->findByPk(Yii::app()->user->id);
             $buh = new Payment();
             $buh->approve = 0;
             $buh->order_id = $orderId;
             $buh->receive_date = date('Y-m-d H:i:s');
             $buh->theme = $order->title;
             $buh->user = $user->email;
             $buh->summ = $paying;
             $buh->payment_type = Payment::OUTCOMING_EXECUTOR;
             $buh->manager = $manag->email;
             /*$buh->details_ya = $user->profile->yandex;
               $buh->details_wm = $user->profile->wmr;
               $buh->details_bank = $user->profile->bank_account;*/
             $buh->save();
         }
         $this->_response->setData(array('project_price' => $payment->project_price, 'to_receive' => $payment->to_receive, 'work_price' => $payment->work_price, 'to_pay' => $payment->to_pay));
     } else {
         $this->_response->setData(array('result' => 'false'));
     }
     $this->_response->send();
 }
Ejemplo n.º 11
0
    $mapInfo = getSelementsInfo($map, ['severity_min' => getRequest('severity_min')]);
    processAreasCoordinates($map, $areas, $mapInfo);
    $allLinks = false;
}
/*
 * Draw map
 */
drawMapConnectors($im, $map, $mapInfo, $allLinks);
if (!isset($_REQUEST['noselements'])) {
    drawMapHighligts($im, $map, $mapInfo);
    drawMapSelements($im, $map, $mapInfo);
}
$expandMacros = getRequest('expand_macros', true);
drawMapLabels($im, $map, $mapInfo, $expandMacros, $graphtheme);
drawMapLinkLabels($im, $map, $mapInfo, $expandMacros, $graphtheme);
if (!isset($_REQUEST['noselements']) && $map['markelements'] == 1) {
    drawMapSelementsMarks($im, $map, $mapInfo);
}
show_messages();
if (getRequest('base64image')) {
    ob_start();
    imagepng($im);
    $imageSource = ob_get_contents();
    ob_end_clean();
    $json = new CJson();
    echo $json->encode(['result' => base64_encode($imageSource)]);
    imagedestroy($im);
} else {
    imageOut($im);
}
require_once dirname(__FILE__) . '/include/page_footer.php';
Ejemplo n.º 12
0
 /**
  * execute when object is serialized
  * @return string
  */
 public function __sleep()
 {
     return CJson::encode($this);
 }
Ejemplo n.º 13
0
 public function testEncode()
 {
     $value = m(["prop0" => "value", "prop1" => a("value0", "value1"), "prop2" => m(["subProp0" => "value0", "subProp1" => "value1"]), "prop3" => a(true, 1234, 56.78)]);
     $json = new CJson($value);
     $encJson = $json->encode();
     $json = new CJson($encJson);
     $success;
     $decMap = $json->decode($success);
     $this->assertTrue($success && $decMap->equals($value));
 }
Ejemplo n.º 14
0
                    }
                }
                break;
            case 'users':
                $users = API::User()->get(['editable' => array_key_exists('editable', $data) ? $data['editable'] : null, 'output' => ['userid', 'alias', 'name', 'surname'], 'search' => array_key_exists('search', $data) ? ['alias' => $data['search'], 'name' => $data['search'], 'surname' => $data['search']] : null, 'searchByAny' => true, 'limit' => $config['search_limit']]);
                if ($users) {
                    CArrayHelper::sort($users, [['field' => 'alias', 'order' => ZBX_SORT_UP]]);
                    if (array_key_exists('limit', $data)) {
                        $users = array_slice($users, 0, $data['limit']);
                    }
                    foreach ($users as $user) {
                        $result[] = ['id' => $user['userid'], 'name' => getUserFullname($user)];
                    }
                }
                break;
        }
        break;
    default:
        fatal_error('Wrong RPC call to JS RPC!');
}
if ($requestType == PAGE_TYPE_JSON) {
    if (isset($data['id'])) {
        echo $json->encode(['jsonrpc' => '2.0', 'result' => $result, 'id' => $data['id']]);
    }
} elseif ($requestType == PAGE_TYPE_TEXT_RETURN_JSON) {
    $json = new CJson();
    echo $json->encode(['jsonrpc' => '2.0', 'result' => $result]);
} elseif ($requestType == PAGE_TYPE_TEXT || $requestType == PAGE_TYPE_JS) {
    echo $result;
}
require_once dirname(__FILE__) . '/include/page_footer.php';