Icontem

File: setmenu/setmenu.php

Recommend this page to a friend!
  Classes of MarPlo  >  AJAX Multi-Level Menu Creator  >  setmenu/setmenu.php  >  Download  
File: setmenu/setmenu.php
Role: Auxiliary data
Content type: text/plain
Description: PHP code that uses the BuildMenu class
Class: AJAX Multi-Level Menu Creator
Edit and generate HTML for multi-level menus
Author: By
Last change:
Date: 6 years ago
Size: 2,407 bytes
 

Contents

Class file image Download
<?php
// Script Menu - http://coursesweb.net/php-mysql/
if(!isset($_SESSION)) session_start();

// HERE add your Admin data, to can save the menu
$admname = 'name';
$admpass = 'password';

// HERE add your data for connecting to MySQL database (MySQL server, user, password, database name)
define('DBHOST', 'localhost');
define('DBUSER', 'root');
define('DBPASS', 'passdb');
define('DBNAME', 'dbname');

     /* From Here no need to modify */

if(!headers_sent()) header('Content-type: text/html; charset=utf-8');      // header for utf-8

// if required data are received
if(isset($_POST['ctgres']) && isset($_POST['saveto']) && isset($_POST['ajx'])) {
  $_POST = array_map('trim', array_map('strip_tags', $_POST));      // removes tags and whitesapces

  include('class.buildmenu.php');        // Include the class that gets and saves categories data
  $obCtg = new buildMenu();

  // if not request to save data, returns data from MySQL; else, to save data
  if(!isset($_POST['sdata'])) echo $obCtg->getCtg();
  // checks if correct Name and Password
  else if(isset($_POST['admname']) && isset($_POST['admpass']) && $_POST['admname'] == $admname && $_POST['admpass'] == $admpass) {
    if(isset($_POST['sdata']) && isset($_POST['admname']) && isset($_POST['admpass'])) {
      // calls the methods to save data, according to 'txt', 'mysql', 'both'
      if($_POST['saveto'] == 'txt') {
        if(file_put_contents('../menus/'. $_POST['ctgres'] .'.txt', $_POST['sdata'])) echo 'Data saved in "'. $_POST['ctgres'] .'.txt"';
        else echo 'Unable to save data in "'. $_POST['ctgres'] .'.txt"';
      }
      else if($_POST['saveto'] == 'mysql') {
        if($obCtg->saveCtg($_POST['sdata'])) echo ' Data saved in "'. $_POST['ctgres'] .'" table';
        else echo ' Unable to save data in "'. $_POST['ctgres'] .'" table';
      }
      else if($_POST['saveto'] == 'both') {
        if(file_put_contents('../menus/'. $_POST['ctgres'] .'.txt', $_POST['sdata'])) echo 'Data saved in "'. $_POST['ctgres'] .'.txt"';
        else echo 'Unable to save data in "'. $_POST['ctgres'] .'.txt"';
        if($obCtg->saveCtg($_POST['sdata'])) echo PHP_EOL .'Data saved in "'. $_POST['ctgres'] .'" table';
        else echo PHP_EOL .'Unable to save data in "'. $_POST['ctgres'] .'" table';
      }
    }
  }
  else echo 'Incorrect Name or Password. Menu Not saved.';
}