function get_form_html($form_id, $id) { ob_start(); ?> <style> .field_name{ width: 20%; } .field input{ width: 100%; margin-left: 0px; } .field .parent{ padding: 0px 0px; } .field select{ width: 100%; } </style> <div id="head_div" style="padding: 5px 0; background-color: #ECECEC; color: #21ACD7; border-radius: 5px;margin-left: auto;display: none; text-align: center; "> </div> <?php $user = new user(); if ($id != 0) { $user->id = $id; $user->getUser(); } ?> <div style="margin-top: 10px; background-color:transparent;padding-bottom: 30px;"> <form action="#" method="post" class="action_form" operation="add" style="width:100%;" > <table style="width:100%;"> <tr> <td class="field_name"> <font>NAME</font> </td> <td class="field"> <div class="parent"> <input value="<?php echo $user->name; ?> " type="text" id="name" required /> </div> </td> </tr> <tr> <td class="field_name"> <font>SHOP</font> </td> <td class="field"> <div class="parent"> <select id="shop" required <?php if ($id != 0) { echo 'disabled = "disabled"'; } ?> > <option value=""></option> <?php $company = new company(); $companies = $company->getCompanies(); if (is_array($companies) and count($companies) != 0) { foreach ($companies as $company) { echo '<option'; if ($user->company_id === $company->id) { echo ' selected '; } echo ' value="' . $company->id . '"'; echo ' >'; echo $company->company_name . ' - ' . $company->company_code; echo '</option>'; } } //print_r($companies); ?> </select> </div> </td> </tr> <tr> <td class="field_name"> <font>TYPE</font> </td> <td class="field"> <div class="parent"> <select id="type" required ="" <?php if ($id != 0) { echo 'disabled = "disabled"'; } ?> > <option value=""></option> <?php $user_type = new user_type(); $user_types = $user_type->getUserTypes(); if (is_array($user_types) and count($user_types) != 0) { foreach ($user_types as $user_type) { echo '<option'; if ($user->user_type_id === $user_type->id) { echo ' selected '; } echo ' value="' . $user_type->id . '"'; echo ' >'; echo $user_type->user_type_name; echo '</option>'; } } //print_r($companies); ?> </select> </div> </td> </tr> <tr> <td class="field_name"> <font>USER NAME</font> </td> <td class="field"> <div class="parent"> <input value="<?php echo $user->user_name; ?> " type="text" id="username" required /> </div> </td> </tr> <tr> <td class="field_name"> <font>PASSWORD</font> </td> <td class="field"> <div class="parent"> <input type="password" value="" autocomplete="off" id="paswd" <?php if ($id == 0) { echo 'required'; } ?> /> </div> </td> </tr> <tr> <td class="field_name"> <font>RE-ENTER PASSWORD</font> </td> <td class="field"> <div class="parent"> <input type="password" value="" autocomplete="off" id="re_password" <?php if ($id == 0) { echo 'required'; } ?> /> </div> </td> </tr> <tr></tr> <tr> <td></td> <td> <div style="padding: 0px 12px;"> <div style="width: 100%; margin-left: -12px; padding: 12px; background-color: #0d92bb; border-radius: 5px; float: left;"> <div style="width: 50%; float: right; "> <input style="width: 100%;" type="submit" value="ADD" /> </div> <div style="width: 50%;"> <input style="width: 100%;" type="reset" value="CANCEL" /> </div> </div> </div> </td> </tr> </table> </form> </div> <script type="text/javascript"> function setFormActionListener(){ $('form.action_form').on('submit', function(e) { e.preventDefault(); var id = 29; var operation = $(this).attr('operation'); if (operation == 'add') { var paswd = $('form input#paswd').val(); var re_password = $('form input#re_password').val(); if(paswd != re_password){ alert('Both passwords are not matching !'); $('form input#paswd').val(''); $('form input#re_password').val(''); $('form input#paswd').focus(); return; } var data = { form_id: id, name: $('form input#name').val(), username: $('form input#username').val(), shop: $('form select#shop').val(), type: $('form select#type').val(), password: paswd } add_form_data(data, function(message) { load_users_list(); alert(message); }, function(message) { alert(message); }); } else if (operation == 'update') { var user_id = $('form.action_form').attr('user_id'); var paswd = $('form input#paswd').val(); if(paswd !== ''){ var re_password = $('form input#re_password').val(); if(paswd != re_password){ alert('Both passwords are not matching !'); $('form input#paswd').val(''); $('form input#re_password').val(''); $('form input#paswd').focus(); return; } } var data = { form_id: id, user_id: user_id, name: $('form input#name').val(), username: $('form input#username').val(), password: paswd } update_form_data(data, function(message) { load_users_list(); alert(message); }, function(message) { alert(message); }); } else { alert("Invalid Operation " + id + ' - ' + operation); } }); }; setFormActionListener(); </script> <?php $form = ob_get_clean(); return $form; }
function get_form_html($form_id, $id) { ob_start(); ?> <div id="head_div" style="height: 150px; width: 320px; background-color: #ECECEC; border-radius: 5px;margin-left: auto;display: none; "> </div> <div style="margin-top: 10px; background-color:transparent;padding-bottom: 30px;"> <style> div#purchace_items td{ border: 1px solid #21ACD7; } div#purchace_items tbody td{ padding: 5px 0 5px 5px; } div#purchace_items tbody td input,div#purchace_items tbody td select{ padding: 0; border: 0; margin: 0; height: 100%; width: 100%; background-color: transparent; } </style> <div id="purchace_items" style="width: 100%; padding: 10px 0; color: #21ACD7;"> <table id="items_table" style="border-collapse: collapse; width: 100%; background-color: #fff; border-radius: 10px; color: #21ACD7;"> <thead style="text-align: center;"> <tr status="not_selected"> <td> # </td> <td> ID </td> <td> NAME </td> <td style=""> USER NAME </td> <td style=""> SHOP </td> <td style=""> TYPE </td> </tr> </thead> <tbody style="padding-left: 3px; text-align: center; "> <?php $user = new user(); $users = $user->getUsers(); $i = 0; if (is_array($users) and count($users) != 0) { $first_admin = true; $first_owner = true; foreach ($users as $user) { ?> <tr id="<?php echo $user->id; ?> " <?php if ($user->user_type_id == 4 and $first_admin) { $first_admin = false; } else { if ($user->user_type_id == 5 and $first_owner) { $first_owner = false; } else { echo ' onclick="select_row(this)"'; } } ?> > <td style="text-align: center;"><?php echo ++$i; ?> </td> <td id="user_id"><?php echo 'USER-' . $user->id; ?> </td> <td id="name"><?php echo $user->name; ?> </td> <td id="user_name"><?php echo $user->user_name; ?> </td> <?php if ($user->user_type_id == 4) { echo '<td>NA</td>'; } else { if ($user->user_type_id == 5) { echo '<td>NA</td>'; } else { ?> <td id="company_id" value="<?php echo $user->company_id; ?> "><?php $company = new company(); $company->id = $user->company_id; $company->getCompany(); echo $company->company_name . ' - ' . $company->company_code; ?> </td> <?php } } ?> <td id="user_type_id" value="<?php echo $user->user_type_id; ?> "><?php $user_type = new user_type(); $user_type->id = $user->user_type_id; $user_type->getUserType(); echo $user_type->user_type_name; ?> </td> </tr> <?php } } else { echo '<tr><td colspan="8"> No User Found </td></tr>'; } ?> </tbody> </table> </div> </div> <script type="text/javascript"> function select_row(row) { var j_row = $(row); if(j_row.attr('status') == 'selected'){ $('table#items_table tr').attr('status', 'not_selected'); $('table#items_table tr').css('background-color', '#FFF'); $('img#edit').css('display', 'none'); $('img#edit_fade').css('display', 'block'); $('img#delete').css('display', 'none'); $('img#delete_fade').css('display', 'block'); }else{ $('table#items_table tr').attr('status', 'not_selected'); $('table#items_table tr').css('background-color', '#FFF'); j_row.attr('status', 'selected'); j_row.css('background-color', '#C0EFFD'); $('img#edit').css('display', 'block'); $('img#edit_fade').css('display', 'none'); $('img#delete').css('display', 'block'); $('img#delete_fade').css('display', 'none'); } } function on_edit_clicked(){ var selected_row = $('tr[status="selected"]'); var id = selected_row.attr('id'); get_form(29, ///user create form function (html, tools){ $('div#form-body').html(html); $('div#content-body-action-tools').html(tools); var form = $('div#form-body').find('form.action_form'); form.attr('operation', 'update'); form.attr('user_id', id); form.find('input[type=submit]').val('UPDATE'); $('div#head_div').html('ID : SHOP - '+id); $('div#head_div').css('display', 'block'); }, function (message){ $('font#section_heading').empty(); $('div#form-body').empty(); alert(message); }, id ); } function on_add_clicked(){ get_form(29, ///user create form function (html, tools){ $('div#form-body').html(html); $('div#content-body-action-tools').html(tools); }, function (message){ $('font#section_heading').empty(); $('div#form-body').empty(); alert(message); } ); } function on_delete_clicked(){ var selected_row = $('tr[status="selected"]'); var id = selected_row.attr('id'); if(confirm('Are you sure you want to delete USER-'+id+' ?' )){ var data = { form_id : 28, user_id : id } delete_form_data(data, function(message) { get_form(28, function(html, tools) { $('div#form-body').html(html); $('div#content-body-action-tools').html(tools); }, function(message) { $('font#section_heading').empty(); $('div#form-body').empty(); alert(message); }); alert(message); }, function(message) { alert(message); }); } } </script> <?php $form = ob_get_clean(); return $form; }
function get_form_html($form_id, $id) { ob_start(); ?> <style> .field_name{ width: 20%; } .field input{ width: 100%; margin-left: 0px; } .field .parent{ padding: 0px 0px; } .field select{ width: 100%; } </style> <div id="head_div" style="padding: 5px 0; background-color: #ECECEC; color: #21ACD7; border-radius: 5px;margin-left: auto;display: none; text-align: center; "> </div> <?php $user = new user(); $user->id = $_SESSION['user_id']; $user->getUser(); $user_type = new user_type(); $user_type->id = $user->user_type_id; $user_type->getUserType(); ?> <div style="margin-top: 10px; background-color:transparent;padding-bottom: 30px;"> <form action="#" method="post" class="action_form" operation="update" style="width:100%;" > <table style="width:100%;"> <tr> <td class="field_name"> <font>USER NAME</font> </td> <td class="field"> <div class="parent"> <input value="<?php echo $user->user_name; ?> " type="text" id="user_name" disabled="disabled" /> </div> </td> </tr> <tr> <td class="field_name"> <font>USER TYPE</font> </td> <td class="field"> <div class="parent"> <input value="<?php echo $user_type->user_type_name; ?> " type="text" id="user_type" disabled="disabled" /> </div> </td> </tr> <tr> <td class="field_name"> <font>PASSWORD </font> </td> <td class="field"> <div class="parent"> <input value="" type="password" id="password_field" required autocomplete="off" /> </div> </td> </tr> <tr> <td class="field_name"> <font>RE-ENTER PASSWORD </font> </td> <td class="field"> <div class="parent"> <input value="" type="password" id="password_copy" required autocomplete="off" /> </div> </td> </tr> <tr></tr> <tr> <td></td> <td> <div style="padding: 0px 12px;"> <div style="width: 100%; margin-left: -12px; padding: 12px; background-color: #0d92bb; border-radius: 5px; float: left;"> <div style="width: 50%; float: right; "> <input style="width: 100%;" type="submit" value="UPDATE" /> </div> <div style="width: 50%;"> <input style="width: 100%;" type="reset" value="CANCEL" /> </div> </div> </div> </td> </tr> </table> </form> </div> <script type="text/javascript"> function setFormActionListener(){ $('form.action_form').on('submit', function(e) { e.preventDefault(); var id = 39; var operation = $(this).attr('operation'); if (operation == 'update') { var password_str = $('form input#password_field').val(); var password_copy = $('form input#password_copy').val(); if(password_str === password_copy){ var data = { form_id: id, password:password_str } update_form_data(data, function(message) { logout(function(){ load_login_page(); }, function(){ load_login_page(); }); alert(message); }, function(message) { alert(message); }); }else{ $('form input#password_field').val(''); $('form input#password_copy').val(''); $('form input#password').focus(); alert("Password and copy not matches !"); } } else { alert("Invalid Operation " + id + ' - ' + operation); } }); }; setFormActionListener(); </script> <?php $form = ob_get_clean(); return $form; }