<?
ob_start();
require_once("functions.php");
    if(!isset($_COOKIE[$admin])){
        header('Location: index.php');
    }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<link href="css/style.css" rel="stylesheet" type="text/css" />

</head>

<body onload="clickMenu('menu')">
<!-- outer -->
<div id="outer">
	<!-- header ----------------------------------------------------->
	<div id="header"> <? include("header.php")?> </div>
	<!-- header -->
    
    <!-- content ---------------------------------------------------->
	<div id="content">
        <!-- con_right --------------------------------------->
	   <div id="con_right">
           <div class="title_page">&nbsp;</div>
            <!--<a href="add_father.php"><div class="add_father"><img src="images/add_48.png" /> إضافة قسم</div></a>-->
           
            <div class="path_page">
             	<div style="text-align:right;">
					<a href="info.php">الرئيسية</a>
					<img src="images/001_27.gif" width="10" height="10" />
                    الموردين
                </div>
            </div>
            <div class="conteaner">
                <div class="details_page">
                 
                </div>
                
                <div class="title_editor">
               	 	<span class="title" style="float:left; margin-left:20px;">
                        
						
                        <a href='add_customer.php' style="text-decoration:none; color: #00FFFF;">
                         	إضافة جديد
                        </a>
                       
                        
                    </span>
                </div>
                
                <div class="editor">
                    <p>
                        <form action="<?$self = $_SERVER['PHP_SELF'];?>" method="post">
                            <table class="table_color">
                                
                                <tr>
                                    <td class="td_table">الاسم</td>
                                    <td>:</td>
                                    <td>
                                        <input class="typ_ro" size="87" type="text" name="sertit" value="<?=$sertit?>" />
                                        <input class="submit" type="submit" name="subsertitle" value="بحث" />
                                    </td>
                                </tr>
                                
                            </table>
                        </form>
                    </p>
                    
                    
                    <?
                        $sertit=$_POST['sertit'];
	$subsertitle=$_POST['subsertitle']; 
	/////////////////////////////////////////////
	if($subsertitle){
			$selcode = "select extention_pic from src_jornal where name LIKE '%$sertit%' and type='customer' and langu='ar'";
            $querycode = mysql_query($selcode);
            $resultrowcode = mysql_num_rows($querycode);
            //في حالة وجد بيانات
            if($resultrowcode > 0){
					///pagenation step 1 $each_page
                    $qury="select * from pagenation where id=1";
                    $resul=mysql_query($qury);
                    while($res = mysql_fetch_array($resul)){
                        extract($res);
                    }
					$each_page=$pagestatic;
					//2 pagenation step 2 $post_count
					$qury="select extention_pic from src_jornal where name LIKE '%$sertit%' and type='customer' and langu='ar'";
					$resul=mysql_query($qury);
					$post_count=mysql_num_rows($resul);
					//3 pagenation step 3 $page_count
					$page_count=ceil($post_count/$each_page);
					//4 pagenation step 4 $page
					if(!isset($_GET['page']) || intval($_GET['page']) <=0){
						$page=1;
					}elseif($_GET['page'] > $page_count){
						$page=$page_count;
					}else{
						$page=$_GET['page'];
					}
					//5 pagenation step 5 $start
					if($post_count >0){
						$start=$each_page*($page-1);
					}
					//6 pagenation step 6 fetch data from db 
					$sel = "select * from src_jornal where name LIKE '%$sertit%' and type='customer' and langu='ar' ORDER BY id DESC limit $each_page OFFSET $start";
					$query = mysql_query($sel);
					$selrow=mysql_num_rows($query);
					//Ýí ÍÇáÉ æÌÏ ÇÎÈÇÑ
					if($selrow){
						$self = $_SERVER['PHP_SELF'];
						echo "<form action='$self' method='post'>";
							echo "<table cellpadding='5' cellspacing='5' style='width:100%' align='center'>";   
                            echo "<th class='th_table' style='width:auto'>الصورة</th>";
							//echo "<th class='th_table'>الكود</th>";
                            echo "<th class='th_table' style='width:auto'>الاسم</th>";
							//echo "<th class='th_table' style='width:auto'>تاريخ الإنشاء</th>";
                            echo "<th class='th_table' style='width:auto'>الظهور</th>";
                            echo "<th class='th_table' style='width:auto'>تعديل</th>";
                            echo "<th class='th_table' style='width:auto'>حذف</th>"; 
							 
							echo "<th class='th_table' style='width:auto'>معلومات</th>"; 
							while($result = mysql_fetch_array($query)){
								extract($result);
								$idd = $id;
								//change pic when active or not active                              
								 if($active != 0){
									$picchange = "<img src='images/apply1.png' width='23' height='23' title='ظاهر' /><br /><b><font color='#5275EA'>ظاهر</font></b>";
								 }else{
									$picchange = "<img src='images/apply.png' width='23' height='23' title='مخفي' /><br /><b><font color='#F00'>مخفي</font></b>";
								 }
								                                																				
								//$path = "../upload/products";
								if($idd%2 != 0){
									$color="bg1";
								}else{$color="bg2";}
								echo "<tr class='$color'>";
									echo "<td align='center'>";
																if($pic != ""){
																	echo "<img src='../upload/customer/$pic$extention_pic' style='padding:5px;' width='30' height='30' title='$desc_pic' />";
																 }else{
																	echo "<img src='images/user_32.png' width='30' height='30' />";
																 }
									echo "</td>";
									//echo "<td align='right'>$code</td>";
									echo "<td align='right'><a title='عنوان الرابط'>$name</a></td>";
                                
                                 //echo "<td align='right'><a title='تاريخ الإنشاء'>$date_creat</a></td>";
									
								  
                                echo "<td align='center'><a href='activeation_customer.php?id=$idd'>$picchange</a></td>";
								
                                echo "<td align='center'><a href='edit_customer_in.php?id=$idd'><img src='images/edi.png' width='23' height='23' title='تعديل' /></a><br />Edit</td>";
								
									echo "<td align='center'><input type='checkbox' value='$idd' name='id[]' /><img src='images/1122.png' width='23' height='23' title='أختر العنصر لحذفه' /></td>";
								
									echo "<td title='تاريخ إنشاء : $date_creat - بواسطة : $create_by - آخر تعديل بواسطة : $last_edit_by - في : $date_last_edit' align='center'><img src='images/info.png' width='23' height='23' /></td>";
								echo "</tr>";	
							}
								echo "<tr>";
									//echo "<td></td>";
									//echo "<td></td>";
									echo "<td></td>";
									echo "<td></td>";
									echo "<td></td>";
									echo "<td></td>";
									echo "<td></td>";
									echo "<td><input class='submit' type='submit' name='delete' value='حذف' /></td>";
									echo "<td></td>";
								echo "</tr>";
							echo "</table>";
						echo "<form>";
						///////////////////////////////////////////////
						//delete
						$delete=$_POST['delete'];
						$id=$_POST['id'];
						if($delete){
							if($id>0){
								foreach($id as $one_by_one){                                           
									$query_delete_message=mysql_query('delete from src_jornal where id ='.$one_by_one.'');
								}
								echo "من فضلك انتظر حتى يتم الحذف <img src='images/loading11.gif' />".
											"<meta http-equiv='refresh' content='1'>";
							}else{echo "<font color='red'>من فضلك اختر سجل أولًا!!!";}
						}
						/////////////////////////////////////////////					
						//pagenation step 7 design button counter
						echo "<div class='counter'>";
						echo "<div align='right'><font color='aqu'>نتائج البحث : $post_count</font></div>";
						if($page_count > 1){
										$first = 1;
										$prev = $page - 1;
										$next = $page + 1;
										$last = $page_count;
										//show first & prev
										if($page > 1){
											echo ' <a href="edit_customer.php?page='.$first.'">الأول</a> ';
											echo ' <a href="edit_customer.php?page='.$prev.'">السابق</a> ';
										}
										// show numbers pages
										for($i=1; $i<=$page_count; $i++){
											if($page != $i){
												echo ' <a href="edit_customer.php?page='.$i.'">'.$i.'</a> ';
											}else{
												echo '<b>'.$i.'</b>';
											}
											
										}
										//show next & last
										if($page < $page_count){
											echo ' <a href="edit_customer.php?page='.$next.'">التالي</a> ';
											echo ' <a href="edit_customer.php?page='.$last.'">الأخير</a> ';
										}
										
						}
						echo "</div>";
						///////////////////////////
						//counter view pagenation
						echo "<span class='view'>
							<form action='$self' method='post'>
								<input type='submit' name='submitview' value='عرض' />
								<input type='text' value='$each_page' size='1' name='view' /> سجل في الصفحة
							</form>
						</span>";
						$submitview = $_POST['submitview'];
						$view = $_POST['view'];
						if($submitview){
							//when text 0 or text
							if(!isset($view) || intval($view) <=0){
								$view=5;
							}
							$update="update pagenation set pagestatic='$view' where id=1";
							$qu=mysql_query($update);
							echo "<meta http-equiv='refresh' content='1'>";
						}
						///////////////////////////
					}else {echo "لا يوجد نتائج مطابقة لبحثك";}	
			}else {echo "لا يوجد نتائج مطابقة لبحثك";}
	}else{
			$sel = "select extention_pic from src_jornal where type='customer' and langu='ar'";
            $query = mysql_query($sel);
            $resultrow = mysql_num_rows($query);
            //في حالة وجد بيانات
            if($resultrow > 0){
                ///pagenation step 1 $each_page
                    $qury="select * from pagenation where id=1";
                    $resul=mysql_query($qury);
                    while($res = mysql_fetch_array($resul)){
                        extract($res);
                    }
                $each_page=$pagestatic;
                //2 pagenation step 2 $post_count
                $qury="select extention_pic from src_jornal where type='customer' and langu='ar'";
                $resul=mysql_query($qury);
                $post_count=mysql_num_rows($resul);
                //3 pagenation step 3 $page_count
                $page_count=ceil($post_count/$each_page);
                //4 pagenation step 4 $page
                if(!isset($_GET['page']) || intval($_GET['page']) <=0){
                    $page=1;
                }elseif($_GET['page'] > $page_count){
                    $page=$page_count;
                }else{
                    $page=$_GET['page'];
                }
                //5 pagenation step 5 $start
                if($post_count >0){
                    $start=$each_page*($page-1);
                }
                //6 pagenation step 6 fetch data from db 
                $sel = "select * from src_jornal where type='customer' and langu='ar' ORDER BY id DESC limit $each_page OFFSET $start";
                $query = mysql_query($sel);
                $selrow=mysql_num_rows($query);
                //Ýí ÍÇáÉ æÌÏ ÇÎÈÇÑ
                if($selrow){
                    $self = $_SERVER['PHP_SELF'];
                    echo "<form action='$self' method='post'>";
                        echo "<table cellpadding='5' cellspacing='5' style='width:100%' align='center'>";
                            echo "<th class='th_table' style='width:auto'>الصورة</th>";
							//echo "<th class='th_table'>الكود</th>";
                            echo "<th class='th_table' style='width:auto'>الاسم</th>";
							//echo "<th class='th_table' style='width:auto'>تاريخ الإنشاء</th>";
                            echo "<th class='th_table' style='width:auto'>الظهور</th>";
                            echo "<th class='th_table' style='width:auto'>تعديل</th>";
                            echo "<th class='th_table' style='width:auto'>حذف</th>";
							
							echo "<th class='th_table' style='width:auto'>معلومات</th>";
                        while($result = mysql_fetch_array($query)){
                            extract($result);
                            $idd = $id;
                             //change pic when active or not active                              
                            if($active != 0){
                                $picchange = "<img src='images/apply1.png' width='23' height='23' title='ظاهر' /><br /><b><font color='#5275EA'>ظاهر</font></b>";
                            }else{
                                $picchange = "<img src='images/apply.png' width='23' height='23' title='مخفي' /><br /><b><font color='#F00'>مخفي</font></b>";
                            }
							                                                                                   
                            //$path = "../upload/products";
                            if($idd%2 != 0){
                                $color="bg1";
                            }else{$color="bg2";}
                            echo "<tr class='$color'>";
                                
								echo "<td align='center'>";
                                                            if($pic != ""){
                                                                echo "<img src='../upload/customer/$pic$extention_pic' style='padding:5px;' width='30' height='30' title='$desc_pic' />";
                                                             }else{
                                                                echo "<img src='images/user_32.png' width='30' height='30' />";
                                                             }
                                echo "</td>";
								//echo "<td align='right'>$code</td>";
                                
                                
                                echo "<td align='right'><a title='اسم المصدر'>$name</a></td>";
                                
                                //echo "<td align='right'><a title='تاريخ الإنشاء'>$date_creat</a></td>";
                                
								
                                echo "<td align='center'><a href='activeation_customer.php?id=$idd'>$picchange</a></td>";
								
                                echo "<td align='center'><a href='edit_customer_in.php?id=$idd'><img src='images/edi.png' width='23' height='23' title='تعديل' /></a><br />Edit</td>";
								
									echo "<td align='center'><input type='checkbox' value='$idd' name='id[]' /><img src='images/1122.png' width='23' height='23' title='أختر العنصر لحذفه' /></td>";
							
									echo "<td title='تاريخ إنشاء : $date_creat - بواسطة : $create_by - آخر تعديل بواسطة : $last_edit_by - في : $date_last_edit' align='center'><img src='images/info.png' width='23' height='23' /></td>";
                            echo "</tr>";
                            
                        }
                            echo "<tr>";
                                //echo "<td></td>";
                                //echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td></td>";
                                echo "<td><input class='submit' type='submit' name='delete' value='حذف' /></td>";
								echo "<td></td>";
								echo "<td></td>";
                            echo "</tr>";
                        echo "</table>";
                    echo "<form>";
                    
                    ///////////////////////////////////////////////
                    //delete news
                    $delete=$_POST['delete'];
                    $id=$_POST['id'];
                    if($delete){
                        if($id>0){
                            foreach($id as $one_by_one){                                              
                            $query_delete_message=mysql_query('delete from src_jornal where id ='.$one_by_one.'');
                            }
							echo "من فضلك انتظر حتى يتم الحذف <img src='images/loading11.gif' />".
                                        "<meta http-equiv='refresh' content='1'>";
                        }else{echo "<font color='red'>من فضلك اختر سجل أولًا!!!";}
                    }
                    /////////////////////////////////////////////
                    
                    //pagenation step 7 design button counter
                	echo "<div class='counter'>";

                echo "<div align='right'><font color='aqu'>إجمالي السجلات : $post_count</font></div>";
                if($page_count > 1){
                                $first = 1;
                                $prev = $page - 1;
                                $next = $page + 1;
                                $last = $page_count;
                                
                                //show first & prev
                                if($page > 1){
                                    echo ' <a href="edit_customer.php?page='.$first.'">الأول</a> ';
                                    echo ' <a href="edit_customer.php?page='.$prev.'">السابق</a> ';
                                }
                                
                                // show numbers pages
                                for($i=1; $i<=$page_count; $i++){
                                    if($page != $i){
                                        echo ' <a href="edit_customer.php?page='.$i.'">'.$i.'</a> ';
                                    }else{
                                        echo '<b>'.$i.'</b>';
                                    }
                                    
                                }
        
                                //show next & last
                                if($page < $page_count){
                                    echo ' <a href="edit_customer.php?page='.$next.'">التالي</a> ';
                                    echo ' <a href="edit_customer.php?page='.$last.'">الأخير</a> ';
                                }
                                
                    }
                echo "</div>";
                
                    ///////////////////////////
                    //counter view pagenation
                    echo "<span class='view'>
                        <form action='$self' method='post'>
                            <input type='submit' name='submitview' value='عرض' />
                            <input type='text' value='$each_page' size='1' name='view' /> سجل في الصفحة
                        </form>
                    </span>";
                    $submitview = $_POST['submitview'];
                    $view = $_POST['view'];
                    if($submitview){
                        //when text 0 or text
                        if(!isset($view) || intval($view) <=0){
                            $view=5;
                        }
                        
                        $update="update pagenation set pagestatic='$view' where id=1";
                        $qu=mysql_query($update);
                        echo "<meta http-equiv='refresh' content='1'>";
                    }
                    ///////////////////////////
            
           		}else{echo "<font color='green'><b>لا يوجد سجلات</b></font>";}
           }else{echo "<font color='green'><b>لا يوجد سجلات</b></font>";}
	}
                    ?>
                </div>
                
            </div>
       </div>
	   <!-- /con_right -->
       
      <!-- con_left ---------------------------------------->
	   <div id="con_left">
            <!-- menu ---------------------------------->
            <div id="menuall"> <? include("menu.php")?> </div>
            <!-- /menu -->
            
            <!-- calender ------------------------------>
            <div id="calender"><embed src="images/Calender.swf" width="235" height="320" /></embed></div>
            <!-- /calender -->
       </div>
	   <!-- /con_left ---------------------------------------->
    </div>
	<!-- /content -->
    
    <!-- footer ----------------------------------------------------->
	<div id="footer"> <? include("footer.php")?> </div>
	<!-- /footer -->
</div>
<!-- /outer -->
</body>
</html>
<?ob_flush();?>