/** * @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'])); }
/** * Creates a standard AJAX submit action * * Will create everything needed to post this form via AJAX to a PHP-side handler. * @param object $controller Handler object * @param string $event Handler method name * @return Form `$this` */ function AjaxSubmitTo($controller, $event) { $s = AjaxAction::Post($controller, $event, "\$(this).serializeArray()"); $this->script("\$('#{self}').submit( function(){ {$s} return false; } );"); return $this; }
/** * High level confirm procedure. * * This will return a standard confirmation dialog that will perform the specified action * when OK is clicked. Will also set a session variable so that the OK action PHP side code * can simply test with <AjaxAction::IsConfirmed>($text_base) if the confirmation was really shown and accepted by the user. * @param string $text_base Text constants basename (like CONFIRMATION). Confirmation will need TITLE_$text_base and TXT_$text_base * @param mixed $controller Controller for OK action * @param string $event Method for OK action * @param string|array $data Data for OK action * @return uiConfirmation Dialog ready to be shown to the user */ public static function Confirm($text_base, $controller, $event = '', $data = '') { $dlg = new uiConfirmation($text_base); $q = self::Url($controller, $event); $data = self::_data($data); $data = "var d = " . ($data ? $data : '{}') . "; for(var n in \$('#{$dlg->id}').data()) if( typeof \$('#{$dlg->id}').data(n) == 'string') d[n] = \$('#{$dlg->id}').data(n); "; $action = "{$data}" . AjaxAction::Post($controller, $event, 'd', $dlg->CloseButtonAction); $dlg->SetOkCallback($action); $_SESSION['ajax_confirm'][$text_base] = md5(time()); $dlg->setData('confirmed', $_SESSION['ajax_confirm'][$text_base]); return $dlg; }
/** * @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'); }