Example #1
0
 function send_params($a, $b, $c, $d)
 {
     $ajax = CJAX::getInstance();
     $params = "\r\n\t\tparams a: {$a}\n\r\n\t\tparams b: {$b}\n\r\n\t\tparams c: {$c}\n\r\n\t\tparams d: {$d}\n\r\n\t\t";
     $ajax->alert($params);
     $ajax->update('params', $params);
 }
Example #2
0
 public function message($text, $type = self::CSS_SUCCESS)
 {
     $ajax = CJAX::getInstance();
     if ($type == self::CSS_SUCCESS || !$type) {
         $css = " cjax_success";
     } else {
         if ($type == self::CSS_WARNING) {
             $css = " cjax_warning";
         } else {
             if ($type == self::CSS_ERROR) {
                 $css = " cjax_error";
             } else {
                 if ($type == self::CSS_PROCESS) {
                     $css = " cjax_process cjax_loading_f";
                 } else {
                     if ($type == self::CSS_INFO) {
                         $css = " cjax_info";
                     } else {
                         if ($type == self::CSS_LOADING) {
                             $css = " cjax_process cjax_loading_f";
                         }
                     }
                 }
             }
         }
     }
     $data = "<div class='cjax_message cjax_message_type{$css}'>{$text}</div>\n";
     return $data;
 }
Example #3
0
 function send_checkbox($check)
 {
     $ajax = CJAX::getInstance();
     if ($check) {
         $ajax->success("Is checked..");
     } else {
         $ajax->warning("Is not checked..");
     }
 }
Example #4
0
 /**
  * 
  * @deprecated
  * @param unknown_type $file_names
  */
 function send_file($file_names = null)
 {
     $ajax = CJAX::getInstance();
     $dir = realpath(dirname(__FILE__) . '/../');
     //directory where the file is uploaded..
     if ($_FILES || $ajax->get('cjax_iframe')) {
         if (!is_writable($dir)) {
             return $ajax->overlayContent("Directory {$dir} is not writeable.\nPermission denied.<br /> (chmod {$dir} 777) or make sure the directory exists.");
         }
         if (empty($_FILES)) {
             return $ajax->overlay("ajax.php?controller=upload_file&function=error");
         }
         $file = $_FILES['my_file'];
         if (!$file['name']) {
             exit('error');
         }
         $temp = $file['tmp_name'] ? $file['tmp_name'] : null;
         $temp = trim($temp, DIRECTORY_SEPARATOR);
         if (@move_uploaded_file($temp, $dir . '/' . $file['name'])) {
             $ajax->success("File uploaded..", 10);
         } else {
             $ajax->warning("Could not move file");
         }
     } else {
         if ($ajax->request()) {
             $ajax->process("Uploading file..", 1000);
             //Ajax request
             //PRE-POST FILE
             if (!$_REQUEST['my_file']) {
                 $ajax->warning("Please select a file");
                 $ajax->focus('my_file');
                 exit;
             }
         }
     }
 }
Example #5
0
 public static function connect($file = null, $port = 80, $local = false)
 {
     $ajax = CJAX::getInstance();
     if (!$port) {
         $port = $ajax->port;
         if (!$port) {
             $port = 80;
         }
     }
     if (!function_exists('fsockopen')) {
         die('no fsockopen: be sure that php function fsockopen is enabled.');
     }
     $fp = @fsockopen($host, $port, $errno, $errstr);
     if (!$fp) {
         return false;
     }
     if ($errstr) {
         die('error:' . $errstr);
     }
     if ($fp) {
         $base = "/";
         @fputs($fp, "GET {$base}{$file} HTTP/1.1\r\n");
         @fputs($fp, "HOST: {$host}\r\n");
         @fputs($fp, "Connection: close\r\n\r\n");
     } else {
         return false;
     }
     $get_info = false;
     $data = array();
     while (!feof($fp)) {
         if ($get_info) {
             $data[] = fread($fp, 1024);
         } else {
             if (fgets($fp, 1024) == "\r\n") {
                 $get_info = true;
             } else {
                 //break;
             }
         }
     }
     fclose($fp);
     return implode($data);
 }
Example #6
0
File: ajax.php Project: glensc/cjax
    protected function _class($controller)
    {
        $raw_controller = $controller;
        $ajax = ajax();
        if ($ajax->config->camelize) {
            $controller = $ajax->camelize($controller, $ajax->config->camelizeUcfirst);
        }
        $_classes = array();
        $_classes[] = 'controller_' . $controller;
        $_classes[] = '_' . $controller;
        $_classes[] = $controller;
        //backward compatiblity with > 5.0-RC2
        $_classes[] = 'controller_' . $raw_controller;
        $_classes[] = '_' . $raw_controller;
        $_classes[] = $raw_controller;
        do {
            $c = $_classes[key($_classes)];
            if (class_exists($c)) {
                return $c;
            }
        } while (next($_classes));
        return $c;
    }
}
define('AJAX_CONTROLLER', 1);
require_once dirname(__FILE__) . '/cjax/cjax.php';
$ajax = CJAX::getInstance();
$controller = $ajax->input('controller');
if ($controller) {
    new ajax($controller);
}
Example #7
0
 /**
  *
  * this is part of the "invalid" plugin which displays an dynamic invalid message.
  */
 function invalid()
 {
     $ajax = CJAX::getInstance();
     $ajax->invalid(array('text1' => 'Enter Value..', 'text2' => 'Enter Value..', 'text3' => 'Enter Value..'));
 }
Example #8
0
 function confirm_action()
 {
     $ajax = CJAX::getInstance();
     $ajax->success("Do something..");
 }
Example #9
0
File: bind.php Project: glensc/cjax
 function bind_elements()
 {
     $ajax = CJAX::getInstance();
     $ajax->info("same command..");
 }
Example #10
0
 function test()
 {
     $ajax = CJAX::getInstance();
     $ajax->success("Testing controller <b>sample</b>.  Works ok.");
 }
Example #11
0
 function fire_alert($message)
 {
     $ajax = CJAX::getInstance();
     $ajax->alert($message);
 }
Example #12
0
 /**
  * get an instance of CJAX
  * with singleton pattern 
  * @return CJAX_FRAMEWORK OBJECT
  */
 public static function getInstance()
 {
     if (self::$CJAX) {
         return self::$CJAX;
     }
     CoreEvents::errorHandlingConfig();
     $ajax = new CJAX_FRAMEWORK();
     if (!defined('JSON_FORCE_OBJECT')) {
         define('JSON_FORCE_OBJECT', 16);
     }
     if (!isset($ajax->format) || !$ajax->format) {
         $ajax->format = new cjaxFormat();
         $config = new ext();
         if (file_exists($f = CJAX_HOME . '/' . 'config.php')) {
             include $f;
             if (isset($config)) {
                 $config = new ext($config);
             }
         }
         $ajax->config = $config;
         $ajax->initiate($ajax);
         if (!$ajax->isAjaxRequest()) {
             //$ajax->flushCache();
             if (defined('AJAX_CD')) {
                 @setcookie('AJAX_CD', AJAX_CD, null, '/');
             } else {
                 //@setcookie ('AJAX_CD', null, time()-(3600*1000),'/');
             }
         } else {
             if (isset($_COOKIE['AJAX_CD']) && !defined('AJAX_CD')) {
                 define('AJAX_CD', $_COOKIE['AJAX_CD']);
             }
             if (!function_exists('cleanInput')) {
                 function cleanInput($input)
                 {
                     return $input;
                 }
             }
         }
     }
     if ($ajax->config->camelize === null) {
         if (version_compare($ajax->version, '>', '5.0-RC2')) {
             $ajax->config->camelize = true;
         }
     }
     if ($ajax->config->ip_debug) {
         if (is_array($ajax->config->ip_debug)) {
             if (in_array(@$_SERVER['REMOTE_ADDR'], $ajax->config->ip_debug)) {
                 $ajax->config->ip_debug = false;
             }
         } else {
             if (@$_SERVER['REMOTE_ADDR'] != $ajax->config->ip_debug) {
                 $ajax->config->ip_debug = false;
             }
         }
     }
     if ($ajax->config->caching) {
         if (isset($_SERVER['REQUEST_URI'])) {
             $ajax->crc32 = crc32($_SERVER['REQUEST_URI']);
             $cache = $ajax->readCache('cjax-' . $ajax->crc32);
             $ajax->caching = $cache;
         }
     }
     if ($ajax->config->debug) {
         @ini_set('display_errors', 1);
         @ini_set('log_errors', 1);
     }
     if (!($js_dir = $ajax->config->js_path)) {
         if (@is_dir('cjax/')) {
             $js_dir = "cjax/core/js/";
         } else {
             if (@is_dir('core/js/')) {
                 $js_dir = "core/js/";
             } else {
                 if (@is_dir('../cjax')) {
                     $js_dir = "../cjax/core/js/";
                 } else {
                     if (@is_dir('../../cjax')) {
                         $js_dir = "../../cjax/core/js/";
                     } else {
                         if (@is_dir('../../../cjax')) {
                             $js_dir = "../../../cjax/core/js/";
                         } else {
                             die("Cannot find the correct path to Js directory.");
                         }
                     }
                 }
             }
         }
         $error = error_get_last();
         if ($error && preg_match('%.*(open_basedir).*File\\(([^\\)]+)%', $error['message'], $match)) {
             die(sprintf('Restriction <b>open_basedir</b> is turned on. File or directory %s will not be accessible while this setting is on due to security directory range.', $match[2]));
         }
     }
     $ajax->js($js_dir);
     return self::$CJAX = $ajax;
 }
Example #13
0
 /**
  * Submit a form
  *
  * @param require string $url  url where the request will be sent to
  * @param require string $form_id  the form id
  * @param optional string $container_id = null  alternative element where to load the response
  * @param optional string $confirm  ask before sending the request
  * @return unknown
  */
 public function form($url, $form_id = null, $container_id = null, $confirm = null)
 {
     $ajax = CJAX::getInstance();
     $out = array();
     $out['do'] = '_form';
     $out['url'] = $url;
     if ($form_id) {
         $out['form_id'] = $form_id;
     }
     if (!is_null($container_id)) {
         $out['container'] = $container_id;
     }
     if (!is_null($ajax->text)) {
         $out['text'] = $ajax->text;
     } elseif ($ajax->text === false) {
         $out['text'] = 'Loading...';
     }
     if ($confirm) {
         $out['confirm'] = $confirm;
     }
     if (is_array($ajax->post)) {
         $args = http_build_query($ajax->post);
         $out['args'] = $args;
         $out['post'] = true;
     } else {
         $out['post'] = 1;
     }
     $xml = $this->xmlItem($this->xml($out), 'form', 'api');
     return $xml;
 }