| Server IP : 192.169.170.185 / Your IP : 216.73.216.97 Web Server : Apache System : Linux p3plmcpnl495852.prod.phx3.secureserver.net 4.18.0-553.52.1.lve.el8.x86_64 #1 SMP Wed May 21 15:31:29 UTC 2025 x86_64 User : akhilnew ( 1712764) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/akhilnew/www/cropandweed/admin/ |
Upload File : |
<?php
if($opt1 && ($opt1 === 'add' OR $opt1 === 'edit')):
if($opt1 === 'edit'):
$stmt = $mysqli->prepare("SELECT $firstcol, category, subcategory, name, content, catsortnumber, sortnumber, status FROM $table WHERE $firstcol = ? LIMIT 1") or die($mysqli->error);
$stmt->bind_param('i', $opt2);
$stmt->execute();
$stmt->store_result();
$count_rows = $stmt->num_rows();
$stmt->bind_result($id, $category, $subcategory, $name, $content, $catsortnumber, $sortnumber, $status);
$stmt->fetch();
$stmt->close();
if($count_rows !== 1):
die('Invalid data selection.');
endif;
$name = html_entity_decode($name);
$content= html_entity_decode($content);
else:
$id = '';$category = '';$subcategory = '';$name = '';$content = '';$catsortnumber = '';$sortnumber = '';$status = 'enabled';
endif;
function categories()
{
global $mysqli, $table;$html = '';
$stmt = $mysqli->prepare("SELECT TRIM(category) FROM $table GROUP BY TRIM(category) ORDER BY TRIM(category) ASC") or die($mysqli->error);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($category);
while($stmt->fetch()):
$html .= $category ? '<option value="'.$category.'">'.$category.'</option>' : '';
endwhile;
$stmt->close();
return $html;
}
$categories = categories();
function subcategories()
{
global $mysqli, $table;$html = '';
$stmt = $mysqli->prepare("SELECT TRIM(subcategory) FROM $table GROUP BY TRIM(subcategory) ORDER BY TRIM(subcategory) ASC") or die($mysqli->error);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($subcategory);
while($stmt->fetch()):
$html .= $subcategory ? '<option value="'.$subcategory.'">'.$subcategory.'</option>' : '';
endwhile;
$stmt->close();
return $html;
}
$subcategories = subcategories();
$checked = $opt1 === 'add' ? 'checked' : '';
$status = $status === 'enabled' ? 'checked' : '';
echo <<<EOJ
<input type="hidden" name="dataid" value="{$id}" readonly />
<div class="head white">
<button type="button" class="waves-effect btn-flat" onclick="history.back()"><i class="material-icons">keyboard_return</i></button>
<button type="submit" class="waves-effect btn-flat blue accent-3">submit</button>
</div>
<div class="body white">
<div class="row">
<div class="col s12 m3 l3">
<label for="category">category<b class="red-text right">*</b></label>
<input type="text" name="category" value="{$category}" id="category" />
</div>
<div class="col s12 m3 l3">
<label for="categorylist">category list</label>
<select name="categorylist" id="categorylist" class="browser-default" onchange="this.form.category.value=this.value;">
<option value="" selected>Select category</potion>
{$categories}
</select>
</div>
<div class="col s12 m3 l3">
<label for="subcategory">sub category</label>
<input type="text" name="subcategory" value="{$subcategory}" id="subcategory" />
</div>
<div class="col s12 m3 l3">
<label for="subcategorylist">sub category list</label>
<select name="subcategorylist" id="subcategorylist" class="browser-default" onchange="this.form.subcategory.value=this.value;">
<option value="" selected>Select sub category</potion>
{$subcategories}
</select>
</div>
</div>
<div class="row">
<div class="col s12 m12 l12">
<label for="name">editor name<b class="red-text right">*</b></label>
<input type="text" name="name" value="{$name}" id="name" />
</div>
</div>
<div class="row">
<div class="col s12 m12 l12">
<label for="content">content</label>
<input type="text" name="content" value="{$content}" id="content" />
</div>
</div>
<div class="row">
<div class="col s12 m6 l6">
<label for="catsortnumber">category sort number<b class="red-text right">*</b></label>
<input type="text" name="catsortnumber" value="{$catsortnumber}" maxlength="6" id="catsortnumber" class="int" onpaste="return false" />
</div>
<div class="col s12 m6 l6">
<label for="sortnumber">sort number</label>
<input type="text" name="sortnumber" value="{$sortnumber}" maxlength="6" id="sortnumber" class="int" onpaste="return false" />
</div>
</div>
<div class="row" style="margin-top:10px">
<div class="col s12 m12 l12">
<div class="chklab left">
<label for="applytoall"><input type="checkbox" name="applytoall" value="Y" id="applytoall" />apply to all</label>
</div>
<div class="chklab left">
<label for="status"><input type="checkbox" name="status" value="enabled" id="status" {$status} />status</label>
</div>
</div>
</div>
</div>
EOJ;
else:
$keyword = htmlentities("%$keyword%");
if($opt1 === 'search'):
$stmt = $mysqli->prepare("SELECT * FROM $table WHERE (name LIKE ? OR content LIKE ?)") or die($mysqli->error);
$stmt->bind_param('ss', $keyword, $keyword);
$stmt->execute();
$stmt->store_result();
$total_rows = $stmt->num_rows();
$stmt->close();
else:
$stmt = $mysqli->prepare("SELECT * FROM $table") or die($mysqli->error);
$stmt->execute();
$stmt->store_result();
$total_rows = $stmt->num_rows();
$stmt->close();
endif;
echo <<<EOJ
<div class="head white">
<button type="button" class="waves-effect btn-flat green" onclick="cURL('add')">add new</button>
<button type="submit" class="waves-effect btn-flat h" onclick="sOPT('enabled', '')">enable</button>
<button type="submit" class="waves-effect btn-flat h" onclick="sOPT('disabled', '')">disable</button>
<button type="submit" class="waves-effect btn-flat h" onclick="sOPT('delete', 'Do you really want to delete?')"><i class="material-icons">delete</i></button>
<div class="pagination right"><b class="left">Total Rows : {$total_rows}</b></div>
</div>
<table class="table">
<thead>
<tr>
<th class="xs center-align"><input type="checkbox" name="checkall" id="checkall" value="" /></th>
<th class="xs center-align">s. no.</th>
<th>category</th>
<th>sub category</th>
<th>name</th>
<th class="center-align" nowrap>c. sort</th>
<th class="xs center-align">sort</th>
<th class="sm center-align">status</th>
<th class="lg right-align">creation</th>
<th class="xs center-align">action</th>
</tr>
</thead>
<tbody>
EOJ;
if($opt1 === 'search'):
$stmt = $mysqli->prepare("SELECT $firstcol, category, subcategory, name, content, catsortnumber, sortnumber, status, creation FROM $table WHERE (name LIKE ? OR content LIKE ?) ORDER BY catsortnumber ASC, sortnumber ASC") or die($mysqli->error);
$stmt->bind_param('ss', $keyword, $keyword);
else:
$stmt = $mysqli->prepare("SELECT $firstcol, category, subcategory, name, content, catsortnumber, sortnumber, status, creation FROM $table ORDER BY catsortnumber ASC, sortnumber ASC") or die($mysqli->error);
endif;
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows() > 0):
$stmt->bind_result($id, $category, $subcategory, $name, $content, $catsortnumber, $sortnumber, $status, $creation);
while($stmt->fetch()):
$snum = $snum + 1;
$name = html_entity_decode($name);
$content = html_entity_decode($content);
$statuscolor = $status === 'enabled' ? 'green-text' : 'red-text';
$option = $status === 'enabled' ? 'disabled' : 'enabled';
echo <<<EOJ
<tr>
<td class="center-align"><input type="checkbox" name="dataid[]" value="{$id}" class="checkbox" /></td>
<td class="center-align">{$snum}</td>
<td>{$category}</td>
<td>{$subcategory}</td>
<td>{$name}</td>
<td class="center-align">{$catsortnumber}</td>
<td class="center-align">{$sortnumber}</td>
<td class="center-align"><button type="submit" class="{$statuscolor}" onclick="sOPT('{$option}', '', this)">{$status}</button></td>
<td class="right-align">{$fn->nice_date($creation)}</td>
<td class="center-align">
<button type="button" class="blue-text text-accent-3" onclick="cURL('edit/{$id}')">edit</button>
</td>
</tr>
EOJ;
endwhile;
else:
echo '<tr><td colspan="10" class="center-align">MySQL returned an empty result set (i.e. zero rows).</td></tr>';
endif;
$stmt->close();
echo '</tbody>';
echo '</table>';
endif;
?>