Location: PHPKode > projects > KvCMS Content Management System > kvframework/kvframework/sitehandler/kvframework_markup.class.php
<?php
abstract class kvframework_markup{
  final public static function link_to_remote($text, array $params){
    $func = self::remote_function($params);
    return self::link_to_function($text, $func);
  }

  final public static function link_to_function($text, $func){
    return "<a href=\"#\" onclick=\"$func\">$text</a>";
  }

  final public static function form_remote_tag(array $params){
    $params["parameters"] = "Form.serialize(this)";
    return "<form action=\"".$params['url']."\" method=\"".((array_key_exists("method", $params)) ? $params["method"] : "POST")."\" onsubmit=\"".self::remote_function($params)."\" id=\"".((array_key_exists("id", $params)) ? $params["id"] : "")."\" >";
  }

  final public static function remote_function(array $params){
    $ret = "";
    if(array_key_exists("update", $params)){
      $ret .= "new Ajax.Updater('".$params['update']."', ";
    } else {
      $ret .= "new Ajax.Request(";
    }
    $ret .= "'".$params['url']."', {asynchronous:true, evalScripts:true";
    foreach($params as $par => $act){
      if($par == "complete"){
        $ret .= ", onComplete:function(request){".$act."}";
      } elseif($par == "loading"){
        $ret .= ", onLoading:function(request){".$act."}";
      } elseif($par == "success"){
        $ret .= ", onSuccess:function(request){".$act."}";
      } elseif($par == "failure"){
        $ret .= ", onFailure:function(request){".$act."}";
      } elseif(is_numeric($par)){
        $ret .= ", on".$par.":function(request){".$act."}";
      } elseif($par == "parameters"){
        $ret .= ", parameters:$act";
      }
    }
    $ret .= "}); return false;";
     return $ret;
  }

  final public static function select(array $opts){

    if(!array_key_exists("name", $opts)){
      $opts["name"] = "select";
    }

    if(!array_key_exists("values", $opts)){
      $opts["values"] = array();
    }

    $ret = "";
    $ret .= "<select name='".$opts["name"]."' id='".$opts["name"]."' size='".((array_key_exists("size", $opts)) ? $opts["size"] : 1)."'";
    if(array_key_exists("multiple", $opts) && $opts["multiple"]){
      $ret .= " multiple='multiple'";
    }
    if(array_key_exists("class", $opts)){
      $ret .= " class='".$opts["class"]."'";
    }
    if(array_key_exists("style", $opts)){
      $ret .= " style='".$opts["style"]."'";
    }
    if(array_key_exists("onchange", $opts)){
      $ret .= " onchange=\"".$opts["onchange"]."\"";
    }
    $ret .= ">";

    if(array_key_exists("prompt", $opts) && $opts["prompt"]){
      $ret .= "<option value='0'>-Please Select-</option>";
    } elseif (array_key_exists("include_blank", $opts) && $opts["include_blank"]){
      $ret .= "<option value='0'> </option>";
    }

    foreach($opts["values"] as $v){
      $ret .= "<option value='".$v[1]."'";
      if(array_key_exists("selected", $opts) && ((is_array($opts["selected"]) && in_array($v[1], $opts["selected"])) || (!is_array($opts["selected"]) && $opts["selected"] == $v[1]))){
        $ret .= " selected='selected'";
      }
      $ret .= ">".$v[0]."</option>";
    }

    $ret .= "</select>";

    return $ret;
  }

  final public static function check_box_tag($name, $value, $checked = false, array $opts = array()){
    return "<input type='checkbox' name='".$name."' id='".$name."' value='".$value."' ".(($checked) ? "checked='checked'" : "")." />";
  }

  final public static function hidden_field_tag($name, $value, array $opts = array()){
    return "<input type='hidden' name='".$name."' id='".$name."' value='".$value."' />";
  }
}
?>
Return current item: KvCMS Content Management System