/**
  * @internal Removes a term.
  * 
  * Removes a term from all translations.
  * @param string $term The term to remove
  * @return void
  * @attribute[RequestParam('term','string')]
  */
 function Remove($term)
 {
     default_string("TITLE_REMOVE_TERM", "Remove term");
     default_string("TXT_REMOVE_TERM", "Do you really want to remove this term? This cannot be undone!");
     if (!AjaxAction::IsConfirmed("REMOVE_TERM")) {
         return AjaxAction::Confirm("REMOVE_TERM", 'TranslationAdmin', 'Remove', array('term' => $term));
     }
     $this->ds->ExecuteSql("DELETE FROM wdf_translations WHERE id=?", $term);
     return AjaxResponse::Redirect('TranslationAdmin', 'Translate', array('lang' => $_SESSION['trans_admin_lang'], 'offset' => $_SESSION['trans_admin_offset'], 'search' => $_SESSION['trans_admin_search']));
 }
 /**
  * Returns a list of option elements.
  * 
  * Called via AJAX to dynamically update the control.
  * @attribute[RequestParam('currency','string')]
  * @param string $currency Valid currency string
  * @return <AjaxResponse::Text> Html string with options
  */
 public function ListOptions($currency)
 {
     $samples = $this->getCurrencySamples($currency, 1234.56, true);
     $res = array();
     foreach ($samples as $code => $item) {
         $res[] = "<option value='{$code}'>{$item}</option>";
     }
     return AjaxResponse::Text(implode("\n", $res));
 }
 /**
  * @internal Delete a string
  * @attribute[RequestParam('term','string')]
  */
 function DeleteString($term)
 {
     $ds = model_datasource($GLOBALS['CONFIG']['translation']['sync']['datasource']);
     $ds->ExecuteSql("DELETE FROM wdf_unknown_strings WHERE term=?", $term);
     return AjaxResponse::None();
 }
 /**
  * @internal Create new string handler
  * @attribute[RequestParam('term','string')]
  * @attribute[RequestParam('text','string','')]
  */
 function CreateString($term, $text)
 {
     global $CONFIG;
     $data = array(array('term' => $term));
     $data = json_encode($data);
     $res = $this->request(array('action' => 'add_terms', 'data' => $data));
     if (!$res) {
         return AjaxResponse::Error("Could not create term: " . $this->Lasterror, true);
     }
     if ($text) {
         $text = urldecode($text);
         $data = array(array('term' => array('term' => $term), 'definition' => array('forms' => array($text), 'fuzzy' => 0)));
         $data = json_encode($data);
         $res = $this->request(array('action' => 'update_language', 'language' => $CONFIG['localization']['default_language'], 'data' => $data));
         if (!$res) {
             return AjaxResponse::Error("Could not set initial term content: " . $this->Lasterror, true);
         }
         cache_del('lang_' . $term);
     }
     return $this->DeleteString($term);
 }
Example #5
0
 /**
  * @internal Handles row action clicks and calls the defined handlers (<Table::AddRowAction>)
  * @attribute[RequestParam('action','string')]
  * @attribute[RequestParam('row','string')]
  */
 function OnActionClicked($action, $row)
 {
     if (isset($this->_actionHandler[$action])) {
         $model = $this->_rowModels[$row];
         return call_user_func_array($this->_actionHandler[$action], array($this, $action, $model, $row));
     }
     log_warn("No handler defined for {$action}");
     return AjaxResponse::None();
 }
Example #6
0
/**
 * Terminats the current run.
 * 
 * Will be called from exception and error handlers. You may, call this directly, but we
 * recommend to throw an exception instead. See the WdfException class and it's Raise() method
 * for more about this.
 * Note: This function will call `die()`!
 * @param string $reason The reason as human readable and hopefully understandable text
 * @param string $additional_message More details to be logged
 * @return void
 */
function system_die($reason, $additional_message = '')
{
    if ($reason instanceof Exception) {
        $stacktrace = $reason instanceof WdfException ? $reason->getTraceEx() : $reason->getTrace();
        $reason = logging_render_var($reason);
    }
    if (!isset($stacktrace)) {
        $stacktrace = debug_backtrace();
    }
    if (isset($GLOBALS['system']['hooks'][HOOK_SYSTEM_DIE]) && count($GLOBALS['system']['hooks'][HOOK_SYSTEM_DIE]) > 0) {
        execute_hooks(HOOK_SYSTEM_DIE, array($reason, $stacktrace));
    }
    if (system_is_ajax_call()) {
        $res = AjaxResponse::Error($reason . "\n" . $additional_message, true);
        die($res->Render());
        //		$code = "alert(unescape(".json_encode($reason."\n".$additional_message)."));";
        //		$res = new stdClass();
        //		$res->html = "<script>$code</script>";
        //		die(system_to_json($res));
    } else {
        $stacktrace = system_stacktrace_to_string($stacktrace);
        $res = "<html><head><title>Fatal system error</title></head>";
        $res .= "<body>";
        $res .= "<h1>Fatal system error occured</h1>";
        if (isDev()) {
            $res .= "<pre>{$reason}</pre><pre>{$additional_message}</pre><pre>" . $stacktrace . "</pre>";
        } else {
            $res .= "Fatal System Error occured.<br/>Please try again.<br/>Contact our technical support if this problem occurs again.<br/><br/>Apologies for any inconveniences this may have caused you.";
        }
        $res .= "</body></html>";
        die($res);
    }
}
 /**
  * Let the client reload the current page.
  * 
  * @return AjaxResponse The created response
  */
 public static function Reload()
 {
     return AjaxResponse::Js("document.location.reload();", true);
 }
Example #8
0
 /**
  * @attribute[RequestParam('table','string',false)]
  * @attribute[RequestParam('action','string',false)]
  * @attribute[RequestParam('model','array',false)]
  * @attribute[RequestParam('row','string',false)]
  */
 function DelProduct($table, $action, $model, $row)
 {
     $this->_login();
     // require admin to be logged in
     // we use the ajax confirm features of the framework which require some translated string, so we set them up here
     // normally we would start the sysadmin and create some, but for this sample we ignore that.
     default_string('TITLE_DELPRODUCT', 'Delete Product');
     default_string('TXT_DELPRODUCT', 'Do you really want to remove this product? This cannot be undone!');
     if (!AjaxAction::IsConfirmed('DELPRODUCT')) {
         return AjaxAction::Confirm('DELPRODUCT', 'Admin', 'DelProduct', array('model' => $model));
     }
     // load and delete the product dataset
     $ds = model_datasource('system');
     $prod = $ds->Query('products')->eq('id', $model['id'])->current();
     $prod->Delete();
     // delete the image too if present
     if ($prod->image) {
         $image = __DIR__ . '/../images/' . $prod->image;
         if (file_exists($image)) {
             unlink($image);
         }
     }
     return AjaxResponse::Redirect('Admin');
 }
 /**
  * Returns a list of option elements.
  * 
  * Called via AJAX to dynamically update the control.
  * @attribute[RequestParam('culture_code','string')]
  * @param string $culture_code Selected culture code
  * @return <AjaxResponse::Text> Html string with options
  */
 public function ListOptions($culture_code)
 {
     $this->culture_code = $culture_code;
     $df = array(DateTimeFormat::DF_LONGDATE, DateTimeFormat::DF_SHORTDATE, DateTimeFormat::DF_MONTHDAY, DateTimeFormat::DF_YEARMONTH);
     $tf = array(DateTimeFormat::DF_LONGTIME, DateTimeFormat::DF_SHORTTIME);
     $value = time();
     $ci = Localization::getCultureInfo($culture_code);
     if (!$ci) {
         $ci = Localization::getCultureInfo('en-US');
     }
     $dtf = $ci->DateTimeFormat;
     foreach ($df as $d) {
         foreach ($tf as $t) {
             $sv = $dtf->Format($value, $d) . " " . $dtf->Format($value, $t);
             $res[] = "<option value='" . json_encode(array($d, $t)) . "'>{$sv}</option>";
         }
     }
     return AjaxResponse::Text(implode("\n", $res));
 }
 /**
  * @internal Will create a new sample based on changed settings.
  * 
  * @attribute[RequestParam('append_timezone','bool')]
  * @attribute[RequestParam('timezone','string')]
  * @attribute[RequestParam('dtf','string')]
  * @attribute[RequestParam('culture_code','string')]
  */
 public function RefreshSample($append_timezone, $timezone, $dtf, $culture_code)
 {
     $this->culture_code = $culture_code;
     $this->timezone = $timezone;
     $txt = $this->_sample($dtf);
     if ($append_timezone) {
         $txt .= " {$timezone}";
     }
     $sample = new Control('span');
     $sample->append("({$txt})")->css('color', 'gray');
     return AjaxResponse::Renderable($sample);
 }
Example #11
0
 /**
  * @internal SysAdmin cache manager: delete event.
  * @attribute[RequestParam('key','string',false)]
  */
 function CacheDel($key)
 {
     cache_del($key);
     return AjaxResponse::None();
 }