* @LINK : http://arslan.labguru.com/ - http://clip-bucket.com/
* @License : Attribution Assurance License -- http://www.opensource.org/licenses/attribution.php
* @DATE : Feb 21 2009
* @Version : 1.2
* @CB Version : v2
* @Class : formObj
*/
if (!function_exists('escape_quotes'))
{
function escape_quotes($text)
{
$text = str_replace("\"", """, $text);
$text = str_replace("'", "'", $text);
return $text;
}
}
class formObj
{
var $multi_cat_id = 0;
/**
* FUNCTION USED TO CREATE TEXT FIELD
*/
function createField($field, $multi = FALSE)
{
$field['sep'] = $field['sep'] ? $field['sep'] : '
';
switch ($field['type'])
{
case 'textfield': case "hidden":
case 'password': case "tel":
case 'textarea': case "email":
$fields = $this->createTextfield($field, $multi);
break;
case 'checkbox':
$fields = $this->createCheckBox($field, $multi);
break;
case 'radiobutton':
$fields = $this->createRadioButton($field, $multi);
break;
case 'dropdown':
$fields = $this->createDropDown($field, $multi);
break;
}
return $fields;
}
/**
*
* @param ARRAY $field
* @param BOOLEAN $multi
* @return STRING
*/
function createTextfield($field, $multi = false)
{
$output = "";
switch ($type)
{
case "text": case "textfield":
{
$output .= ' type="text"';
}break;
case "email":
{
$output .= ' type="email"';
}break;
case "password": case "pass":
{
$output .= ' type="password"';
}break;
case "hidden":
{
$output .= ' type="hidden"';
}break;
case "telephone": case "tel":
{
$output .= ' type="tel"';
}break;
case "textarea":
{
$output = '";
}break;
}
$placeholder = $field['placeholder'] ? $field['placeholder'] : $field['title'];
if ($placeholder)
{
$output .= ' placeholder="'.$placeholder.'" ';
}
if (!empty($field['name']))
{
if ($mutli == false)
{
$output .= ' name="' . $field['name'] . '"';
}
else
{
$output .= ' name="' . $field['name'] . '[]"';
}
}
if (!empty($field['id']))
{
$output .= ' id="' . $field['id'] . '"';
}
if (!empty($field['class']))
{
$output .= ' class="' . $field['class'] . '"';
}
if (!empty($field['extra_tags']))
{
$output .= $field['extra_tags'];
}
// Merge everything
return $output . $size . $rows . $value . $closing;
}
/**
* FUNCTION USED TO CREATE TEXT FIELD
* @param name
* @param id
* @param value
* @param class
* @param extra_tags
* @param label
*/
// function createTextfield($field,$multi=FALSE)
// {
//
// //Starting Text Field
// if($field['type']=='textfield')
// $textField = ''.$field['label'].$textField.'';
// else
// $formTextField = $textField;
//
// return $formTextField;
//
// }
/**
* FUNCTION USED TO CREATE CHECK BOXES
* @param name
* @param id
* @param value = array('value'=>'name')
* @param class
* @param extra_tags
* @param label
*/
function createCheckBox($field, $multi = FALSE)
{
//First Checking if value is CATEGORY
if ($field['value'][0] == 'category')
{
$values_array = $field['value'][1][0];
//$field['value'] = '';
//Generate Category list
$type = $field['category_type'] ? $field['category_type'] : 'video';
$catArray = getCategoryList(array("type" => $type));
if (is_array($catArray))
{
$this->multi_cat_id = $this->multi_cat_id + 1;
$params['categories'] = $catArray;
$params['field'] = $field;
if (config('show_collapsed_checkboxes') == 1)
$params['collapsed'] = true;
$this->listCategoryCheckBox($params, $multi);
return false;
}else
return "There is no category to select";
}
$arrayName = $this->rmBrackets($field['name']);
//Creating Fields
if ($multi)
{
global $multi_cat_id;
@$multi_cat_id++;
}
$count = 0;
foreach ($field['value'] as $key => $value)
{
$count++;
if (is_array($values_array))
{
foreach ($values_array as $cat_val)
{
if ($cat_val == $key || $field['checked'] == 'checked')
{
$checked = ' checked ';
break;
}
else
{
$checked = ' ';
}
}
}
if (!$multi)
$field_name = $field['name'];
else
{
$field_name = $field['name'];
$field_name = $this->rmBrackets($field_name);
$field_name = $field_name . $multi_cat_id . '[]';
}
if (!empty($field['id']))
$field_id = ' id="' . $field['id'] . '" ';
if ($count > 0)
echo $field['sep'];
$class = $field['class'];
echo '';
}
}
function listCategoryCheckBoxCollapsed($in, $multi)
{
$cats = $in['categories'];
$field = $in['field'];
$rand = (rand(0, 100000));
if ($field['sep'] == "
")
$field['sep'] = "";
if (!$multi)
$fieldName = $field['name'];
else
{
$fieldName = $field['name'];
$fieldName = $this->rmBrackets($fieldName);
$fieldName = $fieldName . $multi_cat_id . '[]';
}
$display = "none";
$values = $field['value'][1][0];
$Values = array();
if (!empty($values))
foreach ($values as $val)
$Values[] = "|" . $val . "|";
$class = $field['class'];
if ($cats)
{
$output = "";
foreach ($cats as $cat)
{
$checked = "";
if (in_array("|" . $cat['category_id'] . "|", $Values))
$checked = 'checked';
echo "