// 090421 v5 EDITOR
// 090421 v4
// 090326 v3
// 090319 v2
class Control {
protected $columnName, $fieldName, $type , $result ;
public $controlOnly;
public $readOnly;
public $width=400;
public function __construct($input) {
Global $db;
$this->controlOnly=false;
if(is_array($input)){
$rs=$input;
}else{
// String
$rs=$GLOBALS[$input];
}
$this->result =$rs;
// a($this->result);
}
/*
public function setControlOnly($in_boolean) {
if(in_boolean){
$this->controlOnly=true;
}else{
$this->controlOnly=false;
}
} */
public function addCustomRow($displayText="---",$html="") {
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($html,$displayText);
}
}
public function addEmpty($displayText="") {
print '
| '.$displayText.' |
';
}
protected function addTemplate($html,$fieldName="---",$displayText="") {
if($displayText==""){
$displayText=str_replace("_"," ",$fieldName);
$displayText=ucwords($displayText);
}
$output='
| '.nl2br($displayText).': |
'.$html.' |
';
return $output;
}
/* ============================================================== */
/* ============================================================== */
public function addEditor($fieldName, $displayText="",$width=500,$height=700,$type="") {
@require_once("../../fckeditor/fckeditor.php");
$value=$this->result[$fieldName];
if($width!=""){
$width_style=' style="width:'.$width.'px"';
}
$obj_id=$fieldName.'_'.time();
if($this->readOnly){
$output=($value);
}else{
/* ================ */
$fieldname=$fieldName;
$output= '
';
$oFCKeditor = new FCKeditor("$fieldname");
$oFCKeditor->BasePath = '../../fckeditor/';
$oFCKeditor->ToolbarSet ='BasicWord';
$oFCKeditor->Value = "$value";
$oFCKeditor->Height = "$height";
$oFCKeditor->Width = "$width";
$field=$oFCKeditor->CreateHtml();
$output=$field;
/* ================ */
}
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($output,$fieldName,$displayText);
}
}
/* ============================================================== */
public function addText($fieldName, $displayText="",$maxLength=255,$width="") {
$value=htmlspecialchars($this->result[$fieldName]);
if($width!=""){
$width_style=' style="width:'.$width.'px"';
}else{
$width_style=' style="width:'.$this->width.'px"';
}
if($this->readOnly){
$output=$value;
}else{
$output='';
}
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($output,$fieldName,$displayText);
}
}
/* ============================================================== */
public function addTextarea($fieldName, $displayText="",$maxLength=255,$width="") {
$value=$this->result[$fieldName];
if($width!=""){
$width_style=' style="width:'.$width.'px"';
}
$obj_id=$fieldName.'_'.time();
if($this->readOnly){
$output=nl2br($value);
}else{
$output='';
}
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($output,$fieldName,$displayText);
}
}
/* ============================================================== */
public function addSelect($fieldName,$displayText="",$sql,$displayField="name",$valueField="id" ) {
$value=$this->result[$fieldName];
if($value==""){
$value=$_GET[$fieldName];
}
Global $db;
$result = $db->query($sql);
while($array = mysql_fetch_assoc($result)){
if($array[$valueField]==$value){
$selected=' selected';
$selected_value=$array[$displayField];
}else{
$selected="";
}
$print_choice.='
';
}
if($this->readOnly){
$output=$selected_value;
}else{
$output='';
}
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($output,$fieldName,$displayText);
}
}
/* ============================================================== */
public function addYesNo($fieldName, $displayText="",$defaultValue="1") {
$choice[1]='Yes';
$choice[0]='No';
$value=$this->result[$fieldName];
if($value==""){
$value=$defaultValue;
}
if(is_Array($choice)){
$print_choice='';
foreach($choice as $choice_index=>$choice_value){
$obj_id=$fieldName.'_'.$choice_index;
if($choice_index==$value){
$selected=' checked';
$selected_value=$choice_value;
}else{
$selected='';
}
$print_choice.='
';
}
}
if($this->readOnly){
$output=$selected_value;
}else{
$output=$print_choice;
}
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($output,$fieldName,$displayText);
}
}
/* ============================================================== */
public function addCheckbox($fieldName, $displayText="",$choice="") {
$value=$this->result[$fieldName];
$value_array=split(',',$value);
if(is_Array($choice)){
$print_choice='';
foreach($choice as $choice_index=>$choice_value){
$obj_id=$fieldName.'_'.$choice_index;
if(in_array($choice_index,$value_array) && $value!=""){
$selected=' checked';
$selected_value=$choice_value;
}else{
$selected='';
}
$print_choice.='
';
}
}
if($this->readOnly){
$output=$selected_value;
}else{
$output=$print_choice;
}
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($output,$fieldName,$displayText);
}
}
public function addRadio($fieldName, $displayText="",$choice="") {
$value=$this->result[$fieldName];
if(is_Array($choice)){
$print_choice='';
foreach($choice as $choice_index=>$choice_value){
$obj_id=$fieldName.'_'.$choice_index;
if($choice_index==$value){
$selected=' checked';
$selected_value=$choice_value;
}else{
$selected='';
}
$print_choice.='
';
}
}
if($this->readOnly){
$output=$selected_value;
}else{
$output=$print_choice;
}
if($this->controlOnly){
return $output;
}else{
print $this->addTemplate($output,$fieldName,$displayText);
}
}
/* ============================================================== */
/* ============================================================== */
protected function calculate() {
$this->price = number_format($this->price, 2);
$this->total = number_format(($this->price * $this->qty), 2);
}
public function __toString() {
return "You ordered ($this->qty) '$this->name'" . ($this->qty == 1 ? "" : "s") .
" at \$$this->price, for a total of: \$$this->total.";
}
}
?>