Location: PHPKode > projects > MyEasyShop > myEasySHOP/adm_category_operations.php
<?PHP

/****************************************************/
/*		I N C L U D E S 		   					*/
/****************************************************/
require ("etc/myShop.cfg");
require (LIBRARIES. "db_mySQL.inc");
require (LIBRARIES . "bll_category.inc");
require (LIBRARIES . "template.inc");
require (LIBRARIES . "format.inc");
/****************************************************/	

if (!isset($act)) {
	header ("Location: error.php?msg=Parametro%20action%20non%20presente.");
    exit;
}


switch ($act) {

/****************************************************/
/*						U P L O A D					*/
/****************************************************/

case "upload":

	$bll = new bll_category;	
	$category_upload_img = array(
								"id_category" 			=> $id_category,				
								"thumb_image" 			=> $paththumbimage);
	
	if ($fbpaththumbimg_name != "") {
        @copy("$fbpaththumbimg" , "image/imagethumb/$fbpaththumbimg_name")
                or die("Couldn't Upload Your File.");
        $bll->upload_category_imgthumg($category_upload_img);
    }
    header("Location:adm_category_operations.php?act=detail&id_category=$id_category");
    exit;
break;

/****************************************************/
/*						I N S E R T					*/
/****************************************************/
case "insert":
	$bll = new bll_category;
	$category_attributes = array(
								"id_category" 			=> $id_category,				
								"id_category_parent" 	=> $comboparent,
								"name" 					=> $name,
								"description" 			=> $description,					
								"thumb_image" 			=> $paththumbimage,
								"id_status"				=> $combostatus );
	    
    $bll->insert_category($category_attributes);
    header("Location:adm_category_operations.php?act=list_categories");	
    exit;
break;

/****************************************************/
/*						M O D I F Y					*/
/****************************************************/
case "modify":
	
	$bll = new bll_category;
	$category_attributes = array(
								"id_category" 			=> $id_category,				
								"id_category_parent" 	=> $comboparent,
								"name" 					=> $name,
								"description" 			=> $description,					
								"thumb_image" 			=> $paththumbimage,
								"id_status"				=> $combostatus );
	    
    $bll->update_category($category_attributes); 
    header("Location:adm_category_operations.php?act=list_categories");	       
    exit;
break;

/****************************************************/
/*						D E L E T E					*/
/****************************************************/
case "delete":

	if (!empty($id_category)) {		
		$bll = new bll_category;
		if ($bll->delete_category($id_category)) {								
			header("Location:adm_category_operations.php?act=list_categories");	
            exit;
		} else {
			header ("Location: error.php?msg=Errore nella cancellazione della categoria");					
            exit;
		}
	}		
	
break;

/****************************************************/
/*						 D E T A I L				*/
/****************************************************/
case "detail":

// Creazione lista file template.

	$myArray = array("category_detail" => "adm_category_detail.ihtml"); 
	reset ($myArray);	
	$t 	= new Template(TEMPLATES . "admin_category");
	$t->set_file($myArray);	                                                      

	$bll = new bll_category;
	$categorystatusarray = $bll->get_status('tbl_category_info');
	$arrayallcategory = $bll->get_category(-1);		
	$ilunarrayallcategory=count($arrayallcategory);
	$lunvetallstatus = count($categorystatusarray); 
	$sloadcomboparent = "";	
    
	$t->set_var("ADMIN_CATEGORY_ID_LABEL"			, "Id");
	$t->set_var("ADMIN_CATEGORY_PARENT_LABEL"		, "Categoria Padre");	
	$t->set_var("ADMIN_CATEGORY_NAME_LABEL"			, "Nome");
	$t->set_var("ADMIN_CATEGORY_DES_LABEL"			, "Descrizione");
	$t->set_var("ADMIN_CATEGORY_CDATE_LABEL"		, "Data creazione");
	$t->set_var("ADMIN_CATEGORY_MDATE_LABEL"		, "Data ultima modifica");
	$t->set_var("ADMIN_CATEGORY_STATUS_LABEL"		, "Stato");
	$t->set_var("ADMIN_CATEGORY_THUMBIMAGE_LABEL"	, "Path thumb image");
	
	$t->set_var("ADMIN_CATEGORY_IMG_LABEL"			, "Immagine:");
   	$t->set_var("ADMIN_CATEGORY_LINK_UPLOAD"		, "adm_category_operations.php?act=upload");

    if (empty($id_category )) {	// Nuova categoria 	
    	
		$sloadcombostatus = "<SELECT name=combostatus >";		
		for ($i=0;$i<$lunvetallstatus;$i++) {						
			$sloadcombostatus .= "<OPTION value ='".$categorystatusarray[$i]["id_status"]."'>".$categorystatusarray[$i]["status"]."</option>";
		}	
		$sloadcombostatus .= "</SELECT> ";			
		$t->set_var("ADMIN_CATEGORY_STATUS",		"$sloadcombostatus");						
							
		for ($i=0;$i<$ilunarrayallcategory;$i++) {
			$sloadcomboparent = $sloadcomboparent . "<OPTION selected value=".$arrayallcategory[$i]["id_category"].">".$arrayallcategory[$i]["name"]."</OPTION>";
		}								
		$t->set_var("LOAD_COMBO_CATEGORY_PARENT",		"$sloadcomboparent");
		
		// Header tabella.
		$t->set_var("INTE_TAB_IF_NEW_UPDATE"			, "Inserisci nuova categoria");				
		$t->set_var("ADMIN_CATEGORY_NAME_BUT"			, "Accetta");
		$t->set_var("ADMIN_CATEGORY_ID"					, "");
		$t->set_var("ADMIN_CATEGORY_NAME"				, "");
		$t->set_var("ADMIN_CATEGORY_DES"				, "");						
		$t->set_var("ADMIN_CATEGORY_THUMB_IMAGE"		, "");	
		$t->set_var("ADMIN_CATEGORY_CDATE"				, "");	
		$t->set_var("ADMIN_CATEGORY_MDATE" 				, "");		
		$t->set_var("ADMIN_CATEGORY_THUMBIMAGE"			, "");
   	    $t->set_var("ADMIN_CATEGORY_THUMBIMAGE"		    , "noimg.gif");
   	    $t->set_var("ADD_CATEGORY_ADD_MODIFY_LINK"		, "adm_category_operations.php?act=insert");   	    

	} else {	// Modifica categoria
										
		$arraycategory = $bll->get_single_category_status($id_category);												
		$sloadcombostatus = "<SELECT name=combostatus >";		
		for ($i=0;$i<$lunvetallstatus;$i++) {	
			if($categorystatusarray[$i]["id_status"] == $arraycategory["id_status"]){
				$sloadcombostatus .= "<OPTION selected value ='".$categorystatusarray[$i]["id_status"]."'>".$categorystatusarray[$i]["status"]."</option>";
			} else {
				$sloadcombostatus .= "<OPTION value='".$categorystatusarray[$i]["id_status"]."'>".$categorystatusarray[$i]["status"]."</option>";
			}											
		}	
		$sloadcombostatus .= "</SELECT> ";			
		$t->set_var("ADMIN_CATEGORY_STATUS"				, $sloadcombostatus);
		
		for ($i=0;$i<$ilunarrayallcategory;$i++) {			
			if($arrayallcategory[$i]["id_category"] != $id_category) {
				if($arraycategory["id_category_parent"] == $arrayallcategory[$i]["id_category"]) {					
					$sloadcomboparent = $sloadcomboparent . "<OPTION selected value=".$arrayallcategory[$i]["id_category"].">".$arrayallcategory[$i]["name"]."</OPTION>";
				} else {	
					$sloadcomboparent = $sloadcomboparent . "<OPTION  value=".$arrayallcategory[$i]["id_category"].">".$arrayallcategory[$i]["name"]."</OPTION>";							
				}
			}
		}									
		$t->set_var("LOAD_COMBO_CATEGORY_PARENT"		, "$sloadcomboparent");		
				
		// Header tabella.
		$t->set_var("INTE_TAB_IF_NEW_UPDATE"			, "Modifica categoria");
		$t->set_var("ADMIN_CATEGORY_ID"					, $arraycategory["id_category"]);
		$t->set_var("ADMIN_CATEGORY_NAME"				, $arraycategory["name"]);
		$t->set_var("ADMIN_CATEGORY_DES"				, $arraycategory["description"]);	
		$t->set_var("ADMIN_CATEGORY_CDATE"				, format_datetime($arraycategory["cdate"]));
		$t->set_var("ADMIN_CATEGORY_MDATE"				, format_datetime($arraycategory["mdate"]));		

        if($arraycategory["thumb_image"] != ""){
		  $t->set_var("ADMIN_CATEGORY_THUMBIMAGE"			, $arraycategory["thumb_image"]);
        }else {
		  $t->set_var("ADMIN_CATEGORY_THUMBIMAGE"			, "noimg.gif" );
        }
		$t->set_var("ADMIN_CATEGORY_NAME_BUT"			, "Modifica");
		$t->set_var("ADD_CATEGORY_ADD_MODIFY_LINK"		, "adm_category_operations.php?act=modify");
	}
			
	$t->aparse("CATEGORY"								, "category_detail");
	header("Location:adm_category_operations.php?act=list_categories");	
    exit;
break;

/****************************************************/
/*				L I S T _ C A T E G O R I E S		*/
/****************************************************/
case "list_categories":

// Costanti per paginazione.
	
	if(empty($curr_page)){
		$curr_page = 1;
	}
	
// Creazione lista categorie.
	$bll = new bll_category;
	$arrayallcategories = $bll->get_category(-1);
	
// Creazione lista file template.
	$myArray = array("admin_category_template" 		=> 	"adm_category.ihtml",
					 "admin_category_row_template" 	=> 	"adm_category_row.ihtml");
	reset ($myArray);
	$t 	= new Template(TEMPLATES . "admin_category");
	$t->set_file($myArray);	
	
// Elaborazione elenco categorie
	if (count($arrayallcategories) > 0) {
	
		// Header tabella.
		$t->set_var("ADMIN_CATEGORY_LABEL_NAME"			, "Categoria");
		$t->set_var("ADMIN_CATEGORY_LABEL_PARENT"		, "Categoria padre");				
		$t->set_var("ADMIN_CATEGORY_LABEL_C_DATE"		, "Data creazione");
		$t->set_var("ADMIN_CATEGORY_LABEL_M_DATE"		, "Data ultima modifica");
		$t->set_var("ADMIN_CATEGORY_LABEL_STATUS"		, "Stato");  
		$t->set_var("CATEGORY_CURRENT_PAGE"				, $curr_page);
		$t->set_var("CATEGORY_TOTAL_PAGES"				, ceil(count($arrayallcategories)/PAGE_SIZE)); 		
		$t->set_var("ADM_CATEGORY_DETAIL_ADD_LINK"		, "adm_category_operations.php?act=detail");
		$t->set_var("ADMIN_CATEGORY_ROW"				, "");
	
		if ($curr_page > 1) {
			$Offset = PAGE_SIZE * ($curr_page - 1);
		} else {
			$Offset = 1;
		}
					
		$endfor = count($arrayallcategories) - 1;		
		
		if ($endfor >= PAGE_SIZE * $curr_page ) {		
			$endfor = PAGE_SIZE;
		} else {
			if ($curr_page > 1) {
				$endfor = (PAGE_SIZE * $curr_page) - $endfor  + 1;
			}
		}
		
		for ($i=$Offset;$i<($endfor+$Offset);$i++) {								
			$t->set_var("ADM_CATEGORY_DETAIL_MOD_LINK"	, "adm_category_operations.php?act=detail&id_category=" . $arrayallcategories[$i]["id_category"]);			
			$t->set_var("ADMIN_CATEGORY_ID"				, $arrayallcategories[$i]["id_category"]);
			$t->set_var("ADMIN_CATEGORY_NAME"			, $arrayallcategories[$i]["name"]);	
			$t->set_var("ADMIN_CATEGORY_PARENT"			, $arrayallcategories[$i]["parent_name"]);											
			$t->set_var("ADMIN_CATEGORY_C_DATE"			, format_datetime($arrayallcategories[$i]["cdate"]));
			$t->set_var("ADMIN_CATEGORY_M_DATE"			, format_datetime($arrayallcategories[$i]["mdate"]));			
			$t->set_var("ADMIN_CATEGORY_STATUS"			, $arrayallcategories[$i]["status"]);	
						
			if ($i % 2) {
				$t->set_var("CATEGORY_TBLFLDCLASSNAME"	, 'rigaPari');
			} else {
				$t->set_var("CATEGORY_TBLFLDCLASSNAME"	, 'rigaDispari');
			}
			$t->parse("ADMIN_CATEGORY_ROW"				, "admin_category_row_template",true);
		}
	}	
	$t->aparse("admin_category"							, "admin_category_template");	
	//header("Location:adm_category_operations.php?act=list_categories");
    //exit;
break;
}
?>
Return current item: MyEasyShop