Location: PHPKode > projects > as_admintool > asadmintool/as_admintool_stub.php
<?
/**
===========================================================================
* @package as_admintool
* @desc as_admintool_stub.php - empty stub, starting point for creating plugins
* @author Alexander Selifonov <as-hide@address.com>
* @copyright Alexander Selifonov 2007
* @link http://as-works.narod.ru/en/php/
* @version 1.000.000
* modified 03.03.2007 (dd.mm.yyyy)
* Read "as_admintool.htm" for detailed instructions
============================================================================
*/
define('ASADM_STUB','myplugin'); // unique string ID for this plugin module

if(!isset($as_admt_pages)) $as_admt_pages=array();
if(!isset($as_admt_plugins)) $as_admt_plugins=array();

# mandatory string - registering this plugin
CAsAdminTool::RegisterPlugin(ASADM_STUB,'AsAdm_stub_Form','AsAdm_stub_Exec');

/**
* AsAdm_stub_Form - function for drawing client interface page (FORM)
* This function will be called when CAsAdmin::Draw() is drawing all pages.
* param1-3 are the parameters You've passed to CAsAdminTool::AddPage()
* @param array $pginfo : [0] - pageid, [1],[2] - parent table size (width,height)
* @param $param1,$param2,$param3 - user parameters
* @return none
*/
function AsAdm_stub_Form($pginfo,$param1=false, $param2=false, $param3=false) {
  global $as_dbengine, $as_iface, $as_cssclass;
  $pageid=isset($pginfo[0])? $pginfo[0]: 0;
  $lwidth = isset($pginfo[1])? $pginfo[1]: 800;
  $lheight = isset($pginfo[2])? $pginfo[2]: 600;
  $r_width = $lwidth-20;
  $r_height = $lheight-260;
  $self = $_SERVER['PHP_SELF'];
  static $js_drawn = false;
  if(!$js_drawn) { #<3> draw only once !!!
    $js_drawn = true;
     ?>
<script language='javascript'>
var ajax_stub_busy = false;
function AsAdm_RunStub(pageid) {
  if (ajax_stub_busy) return;
  fm = document.getElementById('asadt_stub_'+pageid);
  var xmlreq = NewXMLHttpRequest();
  if(!xmlreq) return false;
  ajax_stub_busy = true;
  document.getElementById('result_'+pageid).innerHTML = '<?=$as_iface['msg_waiting']?>';
  xmlreq.onreadystatechange= function() { //<3>
    if (xmlreq.readyState == 4) { //<3A>
      var spl = xmlreq.responseText.split("{|}");
      delete xmlreq;
      ajax_stub_busy = false;
      if(spl.length < 2) {
        document.getElementById('result_'+pageid).innerHTML ='wrong response from server: '+spl[0];
      }
      else {
        document.getElementById('result_'+pageid).innerHTML = spl[1];
      } //<4>
    } //<3A>
  } //<3>

  xmlreq.open('POST','<?=$self?>',true);
  xmlreq.setRequestHeader("Content-Type", postcont);
  params = 'adm_action_type=<?=ASADM_STUB?>&pageid=' + pageid + '&'+ComputeParamString('asadt_stub_'+pageid);
  xmlreq.send(params);
  return false;
}
</script>
<?
  }
?>
<table id='asadt_tbl_<?=$pageid?>'>
<tr><form name='asadt_stub_<?=$pageid?>'>
<input type='hidden' name='your_param1' value='<?=$param1?>'>
<tr><td>Your entry<br><textarea name='pass_par1' style='width:<?=$r_width?>px; height:160'><?=$r_width?>,<?=$r_height?></textarea></td></tr>
<tr><td><button class='button' name='start' onClick='AsAdm_RunStub(<?=$pageid?>)'>Let's rock !</button> 
</td></tr></form></table>
<div align=center>
<table width='98%'>
<tr><td>Response from server</td></tr>
<tr><td><div id='result_<?=$pageid?>' class='<?=$as_cssclass['resultarea']?>' style='overflow:auto; height:<?=$r_height?>px; width:<?=$r_width?>px;'>&nbsp;</div></td></tr>
</tr>
</table>
</div>
<?
}

/**
* AsAdm_Stub_Exec - function that executes action on server and returns result string.
* @param array $parms, exactly what POST data contained, but converted from UTF-8 if needed
* @return 'delimited' result. I use a string '{|}' as a delimiter.
*/
function AsAdm_Stub_Exec($parms) {
  global $as_dbengine, $as_iface, $as_admt_bckpfolder;
  $pageid = isset($parms['pageid'])? $parms['pageid'] : '1';
  $stubparam = isset($parms['pass_par1'])? $parms['pass_par1'] : 'No text entered !';
  # ... Here You place Your action code, and make a result string in $ret
  $ret = "$pageid{|}You have passed the string: $stubparam";
  return $ret;
}

?>
Return current item: as_admintool