Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Пояснительная записка Закирьянов.docx
Скачиваний:
0
Добавлен:
01.07.2025
Размер:
2.36 Mб
Скачать

Приложение а

Исходный код главной страницы Web-приложения

Index.php:

<?php

session_start();

header("Content-Type: text/html;charset=utf-8");

/*ini_set ("display_errors", "1");

error_reporting (E_ALL);*/

/*include block*/

require_once 'include/defines.php';

require_once 'include/basic_functions.php';

require_once PATH_BASE.'config'.DS.'config.php';

require_once PATH_BASE.'include'.DS.'mysql_connect.php';

/*classes*/

require_once PATH_BASE.'adm'.DS.'class'.DS.'resize-class.php';

require_once PATH_BASE.'include'.DS.'classes'.DS.'statusmessage.php';

require_once PATH_BASE.'include'.DS.'classes'.DS.'profile.php';

/*modules*/

require_once PATH_BASE.'include'.DS.'modules'.DS.'content_function.php';

require_once PATH_BASE.'include'.DS.'modules'.DS.'file_function.php';

require_once PATH_BASE.'include'.DS.'modules'.DS.'html_tag_function.php';

require_once PATH_BASE.'include'.DS.'modules'.DS.'basket_function.php';

require_once PATH_BASE.'include'.DS.'modules'.DS.'search.php';

require_once PATH_BASE.'include'.DS.'values.php';

/*header block*/

require_once 'template/page.php';

?>

defines.php:

<?php

define( 'DS', DIRECTORY_SEPARATOR );

define('HOME_PAGE_LINK', 'http://localhost/work/artposter/');

define('G_CHECK', 1);

define('DEFAULT_LANG', 'rus');

/*base path*/

$basePath = explode(DS, dirname(__FILE__));

array_pop($basePath);

$basePath = implode(DS, $basePath).DS;

define('PATH_BASE', $basePath);

?>

basic_functions.php:

<?php

function getCurrentYear(){

return date("Y");

}

function addSuffixToNumerals($num, $word, $closure){

$one_num = last_int($num, 1);

$two_num = last_int($num, 2);

$finalClose = $closure[0];

if($one_num >= 2 && $one_num <= 4){

$finalClose = $closure[1];

}

if($one_num >= 5 && $one_num <= 9 || $one_num == 0 || $two_num >= 10 && $two_num <= 20){

Продолжение приложения А

$finalClose = $closure[2];

}

return $word.$finalClose;

}

function last_int($num, $numSimbol){

$result = (int)substr($num, strlen($num)-$numSimbol, strlen($num));

return $result;

}

function getValue($postValue, $getValue){

var_dump($postValue);

var_dump($getValue);

}

function getTemplate($template){

if($template == ''){

$tempTemplate = 'index';

}

if($template == 'poster' || $template == 'content' || $template == 'basket'|| $template == 'search'|| $template == 'profile'){

$tempTemplate = $template;

}

return $tempTemplate;

}

function returnURL($href, $type=''){

$resultURL = HOME_PAGE_LINK;

$linkArr = array();

if($type != ''){

$linkArr[] = $type;

}

if($href != ''){

$linkArr[] = $href;

}

if(count($linkArr) > 0){

$resultURL = implode('/', $linkArr);

$resultURL = HOME_PAGE_LINK.$resultURL;

}

return $resultURL;

}

function createBreadCrumb($template, $link = '', $posterName = '', $type = ''){

$resultArr = array();

$resultArr[] = createATag('<strong>Главная</strong>');

switch($template){

case 'content':

switch($type){

case 'contact' :

$resultArr[] = '<span>Контакты</span>';

break;

Продолжение приложения А

case 'production' :

$resultArr[] = '<span>Производство</span>';

break;

}

break;

case 'search' :

$resultArr[] = '<span>Поиск</span>';

break;

case 'poster' :

if($link != ''){

$catInfo = getCurrentCategoryInfo($link);

if($posterName == ''){

$resultArr[] = '<span>'.$catInfo['header'].'</span>';

}

else{

$resultArr[] = createATag($catInfo['header'], $catInfo['link'], 'poster');

$resultArr[] = '<span>#'.$posterName."</span>";

}

}

break;

}

$result = implode('<span>/</span>', $resultArr);

return $result;

}

function createTitle($template, $link = '', $posterName = '', $type = ''){

$resultArr = 'Главная';

switch($template){

case 'content':

switch($type){

case 'contact' :

$resultArr = 'Контакты';

break;

case 'production' :

$resultArr = 'Производство';

break;

}

break;

case 'search' :

$resultArr = 'Поиск';

break;

case 'poster' :

if($link != ''){

$catInfo = getCurrentCategoryInfo($link);

$resultArr = $catInfo['header'];

}

break;

}

$result = $resultArr;

Продолжение приложения А

return $result;

}

function add_recently_watch($poster_id){

if(!empty($_COOKIE['recently'])){

$next_step = count($_COOKIE['recently']);

if(!in_array($poster_id, $_COOKIE['recently'])){

setcookie("recently[$next_step]", $poster_id, time() + 360000000, '/');

}

}

else{

setcookie("recently[0]", $poster_id, time() + 360000000, '/');

}

}

function addMesage($status, $text){

$classMessage = $status;

$_SESSION['service_message']= "<div class='$status'>$text</div>";

}

function writeMessage(){

echo $_SESSION['service_message'];

$_SESSION['service_message'] = '';

}

function currentEmail($email){

return true;

}

?>

config.php:

<?php

$config = array(

'css' => array(

'style.css',

'main_banner.css',

'content_page.css',

'jquery.lightbox-0.5.css',

'cart.css'

),

'js' => array(

'jquery.js',

'jquery.cookie.js',

'horizontal_slider.js',

'main.js',

'jquery.lightbox-0.5.js',

'cart.js'

),

);

$dbConfig = array(

'user' => 'root',

'password' => '11051988',

'db_host' => 'localhost',

'db_base' => 'posters'

);

?>

Продолжение приложения А

mysql_connect.php:

<?php

$connect = mysql_connect($dbConfig['db_host'], $dbConfig['user'], $dbConfig['password'])

or die("Could not connect: ".mysql_error());

mysql_select_db($dbConfig['db_base'])

or die("Could not select database: ".mysql_error());

mysql_query ('SET NAMES UTF8');

?>

values.php:

<?php

/*get or post value*/

$reqLink = $_GET['link'];

$reqId = $_GET['id'];

$reqImageId = $_GET['image_id'];

$type = $_GET['type'];

$action = $_GET['action'];

if(empty($action)){

$action = $_POST['action'];

}

$lastURL = $_SERVER['HTTP_REFERER'];

$delete_action = $_POST['delete_poster'];

$request_action = $_POST['submit'];

/*basic value*/

$allCatSubIdLink = AllCatSubIdLink();

$currentYear = getCurrentYear();

$styles = createCssStylesTags($config['css']);

$scripts = createJSTags($config['js']);

$template = getTemplate($_GET['template']);

$allCategoryList = getAllCategoriesAlphabetical();

$recentlyWatchList = getRecentlyWatchPoster($allCatSubIdLink);

/*user*/

$userLogin = $_POST['email'];

$userPassword = $_POST['password'];

$userName = $_POST['name'];

$userCity = $_POST['city'];

$userPhone = $_POST['phone'];

$statusMessage = new StatusMessage(true);

$user = new Profile($statusMessage);

$userInfo = $user->get_user_info();

$auth = $userInfo['auth'];

/**/

switch($template){

case 'index' :

$bestSalePosterList = getBestSalePosterData($allCatSubIdLink);

/*sliders*/

Продолжение приложения А

$allCategorySlider = createHorizontalSlider('206x206', $allCategoryList, 'main_slider');

$recentlyWatchSlider = createHorizontalSlider('209x198', $recentlyWatchList);

$bestSalePosterSlider = createHorizontalSlider('165x150', $bestSalePosterList);

/*handlist*/

$mainHandlist = createAlphabeticalList(createAllCategoryATagArray($allCategoryList), 5);

break;

case 'poster' :

$posterHandlist = createAlphabeticalList(createAllCategoryATagArray($allCategoryList), 2);

$catInfo = getCurrentCategoryInfo($reqLink);

$allPosterInCatArray = getAllPosterInCat($catInfo['id'], $catInfo['link']);

$currentPosterInfo = getCurrentPosterInfo($reqId, $allPosterInCatArray, $catInfo['link']);

add_recently_watch($currentPosterInfo['id']);

$currentPosterSize = getCurrentPosterSize($currentPosterInfo['id'], $currentPosterInfo['link']);

$currentPosterSizeI = getCurrentSizeI($currentPosterSize, $reqImageId);

$currentImage = createCurrentPosterImage($currentPosterSize[$currentPosterSizeI]['big_image'], $currentPosterSize[$currentPosterSizeI]['image']);

$posterSizeBlock = createSizeChage($currentPosterSize, $currentPosterSizeI);

/*sliders*/

$recentlyWatchSlider = createHorizontalSlider('140x110', $recentlyWatchList);

$allPosterInCatSlider = createHorizontalSlider('209x198', $allPosterInCatArray, '', 'poster', $currentPosterInfo['id']);

break;

case 'content' :

$contentHandlist = createAlphabeticalList(createAllCategoryATagArray($allCategoryList), 1);

break;

case 'profile' :

$basketList = create_cart($userInfo);

$contentHandlist = createAlphabeticalList(createAllCategoryATagArray($allCategoryList), 1);

$recentlyWatchSlider = createHorizontalSlider('147x135', $recentlyWatchList);

break;

case 'basket' :

$basketList = create_cart($userInfo);

$contentHandlist = createAlphabeticalList(createAllCategoryATagArray($allCategoryList), 1);

break;

}

$breadCrumb = createBreadCrumb($template, $reqLink, $currentPosterInfo['header'], $type);

$titlePage = createTitle($template, $reqLink, $currentPosterInfo['header'], $type);

switch($action){

case 'logout' :

$user->logout();

header("Location:".HOME_PAGE_LINK); exit;

break;

case 'authorization' :

$user->auth($userLogin, $userPassword);

header("Location:".HOME_PAGE_LINK); exit;

break;

case 'register' :

$user->register($userLogin, $userPassword, $userName, $userCity, $userPhone);

header("Location:".HOME_PAGE_LINK); exit;

Продолжение приложения А

break;

case 'change_data' :

$user->change($userInfo['id'], $userLogin, $userPassword, $userName, $userCity, $userPhone);

header("Location:$lastURL"); exit;

break;

case 'add_to_cart':

addToCart($auth, $reqImageId, $userInfo);

header("Location:$lastURL"); exit;

break;

case 'send_cart':

$mTitle = 'Zakaz postera';

$mAdress = 'info@artposters.kz';

//$mAdress = 'developer@illustrate.kz';

$idList = getIdList($_REQUEST['id_poster']);

if(!empty($delete_action)){

deletePosterInBasket($idList, $userInfo);

}

else{

$requestMake = makeRequest($idList, $auth, $userInfo);

if($requestMake['send_status']){

$mText = $requestMake['message'];

$sendStatus = mailer($mAdress, $mTitle, $mText);

if($sendStatus){

addMesage('complete', 'Заявка отправлена');

deletePosterInBasket($idList, $userInfo);

}

else{

addMesage('error', 'При отправке сообщения возникла ошибка, попробуйте еще раз');

}

}

}

if($auth){

header("Location:".HOME_PAGE_LINK.'profile'); exit;

}

else{

header("Location:".HOME_PAGE_LINK.'basket'); exit;

}

break;

}

$profileLink = returnURL('profile');

if(!$auth){

$profileLink = "#\" onclick=\"showPopupAlert('login_popup'); return false;";

}

if($template == 'profile' && !$auth){header("Location:".HOME_PAGE_LINK);}

$authMessage = $statusMessage->printMessage('auth');

$registerMessage = $statusMessage->printMessage('register');

$changeMessage = $statusMessage->printMessage('change');

if($authMessage != ''){

$addAction = "showPopupAlert('login_popup');";

}

if($registerMessage != ''){

$addAction = "showPopupAlert('register_popup');";

}

if($changeMessage != ''){

$addAction = "showPopupAlert('change_popup');";

}

?>

119