| Current Path : /var/www/html/ebilikparlimen1/ebilik/ks_builtin/ |
| Current File : /var/www/html/ebilikparlimen1/ebilik/ks_builtin/data_modify.php |
<?php
include_once '../library.php';
//check is user authenticated
$isAuth = CUSTOM_User::checkAuthentication ();
if (! $isAuth) {
$red = urlencode ( $_SERVER ['REQUEST_URI'] );
header ( "Location: ../ks_user/login.php?msg=notlogin&red=$red" );
exit ();
}
$fid = ( int ) $_GET ['fid'];
$id = (int) $_GET ['id'];
$objForm = new KS_Form ();
$objForm->setId ( $fid );
if (! $objForm->exists ()) {
include_once '../layout_header.php';
$msg_desc = "Error! Specified form ($fid) doesn't exist. Perhaps it has been deleted? Please update your List property.";
$showMessageBoxType = 'notice';
$showMessageBox = 1;
echo "<div class=" . $showMessageBoxType . ">
<div class=\"message_box_content\">" . $msg_desc . "</div>
<div class=\"clearboth\"></div></div>
";
exit ();
}
$objForm->select ();
$countable = $objForm->getMultiple ();
$tablename = $objForm->getTable ();
$arrFields = KS_Field::listFieldsByTable ( $tablename, 'sf_fieldname', '', 0, 0 );
$orders = $objForm->getOrders ();
$matchfield = explode ( ",divlabel", $orders );
function handle_existing_tablename (&$usedField, $key, $tn) {
//if already has $tn prefix... remove it..
if (preg_match('/\./', $usedField)) {
$arrTableField = explode (".", $usedField);
$usedField = $arrTableField [1];
}
}
array_walk ($matchfield, 'handle_existing_tablename', $tablename);
//get user's role from session data
$ks_session = CUSTOM_User::getSessionData ();
$usr_role = $ks_session ['USR_ROLE'];
$alltable = $objForm->getTable ();
//by default use first table
$piece = explode ( ";", $alltable );
$findlast = count ( $piece );
$findlast = $findlast - 1;
$firstTable = $piece [$findlast];
//acl start here
$useAcl = $firstTable."(form_id" . $fid.")";
//acl start here
//$useAcl = "form_id" . $fid;
//this ACL is for controlling Modify button
$objAcl = new KS_Acl ();
$isAllowModify = $objAcl->isAllowed ( $usr_role, $useAcl, 'modify' );
if ($isAllowModify) {
//do something if allowed
} else {
//do something else
}
include_once '../layout_header.php';
?>
<script>
$(document).ready(function(){
$("#formModify").validationEngine();
});
</script>
<?php
if ($orders != '') {
?>
<ul class="breadcrumb">
<li><i class="glyphicon glyphicon-home"></i> <a
href="<?=KSCONFIG_URL;?>home.php">Home</a></li>
<li class="dropdown">Display</li>
</ul>
<p align="left"><?=KS_Form::getTitleInstruction ( 21, $fid );?></p>
<form action="data_modify_handler.php" method="post"
enctype="multipart/form-data" name="formModify" id="formModify">
<table width="98%" border="0" align="center" cellpadding="4"
cellspacing="1" class="table table-hover table-bordered">
<tbody>
<?php
$arrMultiple = array();
$counterF = 1;
$prefix = "fld";
$useAllTable = explode ( ";", $tablename );
for($i = 1; $i <= count ( $matchfield ); $i ++) {
$fieldName = $matchfield [$i];
//echo $fieldName = $curField ['fieldname'];
preg_match ( "/^[a-z0-9]+/", $fieldName, $arrFoundPrefix );
$fieldPrefix = ucfirst ( $arrFoundPrefix [0] );
$fieldNameTruncated = preg_replace ( "/^[a-z0-9]+_/", "", $fieldName );
$fieldNameTruncated = preg_replace ( '/_(\w{1})/e', "strtoupper('\\1')", $fieldNameTruncated );
$fieldNameTruncated = ucfirst ( $fieldNameTruncated );
//find new tn
$sqlFindTypeKS1 = "SELECT sf_tablename FROM ks_field WHERE sf_fieldname = '$fieldName'";
$sf_type1 = $ks_db->fetchOne ( $sqlFindTypeKS1 );
$sqlFindTypeKS = "SELECT sf_type FROM ks_field WHERE sf_fieldname = '$fieldName' AND sf_tablename = '$sf_type1'";
$sf_type = $ks_db->fetchOne ( $sqlFindTypeKS );
$fieldType = $sf_type;
$fieldClass = "KS_Field_" . ucfirst ( $fieldType );
$objectName = "$prefix" . $fieldPrefix . $fieldNameTruncated;
$test = "$" . $objectName;
if ($fieldName != '') {
$test = new $fieldClass ( $sf_type1, $fieldName );
$test->select ();
//get primary column
$sqlPrimary = "SHOW KEYS FROM $sf_type1 WHERE Key_name ='PRIMARY'";
$stmtPrimary = $ks_db->query ( $sqlPrimary );
while ( true == ($rowPrimary = $stmtPrimary->fetch ()) ) {
$primaryCol = $rowPrimary ['Column_name'];
$arrMultiple[] .= $rowPrimary ['Column_name'];
}
if (in_array($fieldName, $arrMultiple)){ // handle multiple primary key
$fieldNamePri = preg_replace ( '/_(\w{1})/e', "strtoupper('\\1')", $fieldName );
$test->setValue ( $_GET[$fieldNamePri] );
}else {
$sqlGetField = "SELECT $fieldName FROM $sf_type1 WHERE $primaryCol = '$id'";
$getFieldValue = $ks_db->fetchOne ( $sqlGetField );
$test->setValue ( $getFieldValue );
}
if ($sf_type == "file") {
echo "<input type=\"hidden\" name=\"1232**_$fieldName\" value=\"$getFieldValue\" />";
}
?>
<tr>
<td width="30%" align="right"><?=$test->getLabel ();?> : </td>
<td width="70%" align="left"><?php
if (in_array($fieldName, $arrMultiple)){ ?> <?=$test->display ();?> <input
type="hidden" name="<?=$fieldNamePri;?>" id="<?=$fieldNamePri;?>"
value="<?=$_GET[$fieldNamePri];?>" /> <?php }else if ($fieldName != $primaryCol) {
?> <?=$test->modify ();?> <?php
} else {
?><?=$test->display ();?><span style="display: none"><?=$test->modify ();?></span><?php
}
?> </td>
</tr>
<?php
}
} //}
?>
<tr>
<td> </td>
<td>
<button type="submit" name="Submit" class="btn btn-primary"><i class="fa fa-save"></i> Save</button>
<input type="hidden" name="id" id="id" value="<?=$id;?>" /> <input
type="hidden" name="fid" id="fid" value="<?=$fid;?>" /> </td>
</tr>
</tbody>
</table>
</form>
<p align="left"><?=KS_Form::getTitleInstruction ( 22, $fid );?></p>
<?php
} else {
?>
<p align="center" class="font-error">Please design your form first at
tab editor.</p>
<?php
}
include_once '../layout_footer.php';
?>