Subversion Repositories artstore

Rev

Blame | Last modification | View Log | RSS feed

<?php
/***************************************************************************
 *   Copyright (C) 2014 by Computerhaus GmbH                               *
 *   m@kom.at                                                              *
 *                                                                         *
 *   COPYRIGHT (C) 2014      by COMPUTERHAUS EDV-HANDELS GMBH. ALL RIGHTS  *
 *   RESERVED. NO PART OF THIS PRGORAM OR PUBLICATION MAY BE REPRODUCED,   *
 *   TRANSLATED, TRANSCRIBED, STORED IN A RETRIEVAL SYSTEM, OR TRANSLATED  *
 *   INTO ANY LANGUAGE OR COMPUTER LANGUAGE IN ANY FORM OR BY ANY MEANS,   *
 *   ELECTRONIC, MECHANICAL, MAGNETIC, OPTICAL, CHEMICAL, MANUAL, OR       *
 *   OTHERWISE, WITHOUT THE PRIOR WRITTEN PERMISSION OF:                   *
 *                                                                         *
 *                 COMPUTERHAUS EDV-HANDELS GES.M.B.H                      *
 *                                                                         *
 *               WIENERSTRASSE 26 - 8605 KAPFENBERG - AUSTRIA              *
 *                                                                         *
 ***************************************************************************/

spl_autoload_register(null, false );
spl_autoload_extensions( '.php, .class.php' );

require_once 'includes/configuration.php';

function classesLoader($class) {
        $filename = strtolower($class) . '.php';
        $file = DIR_WS_INCLUDES . $filename;
        if( !file_exists($file) )
                return false;
        include $file;
}

spl_autoload_register('classesLoader');

$db = new Database;


$return_data = array();
// $return_data['error_text'] = "";

if ( isset($_GET) ) {
        error_log( 'backend GET DATA: ' . print_r( $_GET, true ) );
}
if ( isset($_POST) ) {
        error_log( 'backend POST DATA: ' . print_r( $_POST, true ) );
}

if ( ( isset ( $_GET ) ) && ( Core::array_has_content($_GET) ) && ( array_key_exists('action',$_GET) ) ) {

//      $colli_uuid = ( ( ( array_key_exists('colli_uuid',$_GET) ) && ( is_numeric ( $_GET['colli_uuid'] ) ) ) ? $_GET['colli_uuid'] : false );
        $colli_uuids = array();
        if ( array_key_exists('colli_uuid',$_GET) ) {
                if ( strpos( $_GET['colli_uuid'], "\n" ) !== false ) {
                        if ( Core::array_has_content( $colli_uuid_data = explode("\n",$_GET['colli_uuid']) ) ) {
                                foreach( $colli_uuid_data AS $colli_uuid ) {
                                        $colli_uuids[] = $colli_uuid;
                                }
                        }
                } elseif ( is_numeric($_GET['colli_uuid']) ) {
                        $colli_uuids[] = $_GET['colli_uuid'];
                }
        }
        $sector_uuid = ( ( ( array_key_exists('sector_uuid',$_GET) ) && ( is_numeric ( $_GET['sector_uuid'] ) ) ) ? $_GET['sector_uuid'] : false );
        $store_type = ( ( ( array_key_exists('store_type',$_GET) ) && ( !empty( $_GET['store_type'] ) ) ) ? $_GET['store_type'] : false );
        $additional_type = ( ( ( array_key_exists('additional_type',$_GET) ) && ( !empty( $_GET['additional_type'] ) ) ) ? $_GET['additional_type'] : false );
        $objinfo_uuid = ( ( ( array_key_exists('objinfo_uuid',$_GET) ) && ( !empty( $_GET['objinfo_uuid'] ) ) ) ? $_GET['objinfo_uuid'] : false );

        switch ( $_GET['action'] ) {
                case 'check_colli_uuid':
                        $return_data['success'] = false;
//                      if ( strpos($colli_uuid,"\n") !== false && Core::array_has_content( $colli_uuids = implode("\n",$colli_uuid) ) ) {
                        if ( Core::array_has_content($colli_uuids) ) {
                                $count_ok = 0;
                                $count_nok = 0;
                                $row = 0;
                                $infos = array();
                                $errors = array();
                                foreach( $colli_uuids AS $colli_uuid ) {
                                        $row++;
                                        if ( !empty($colli_uuid) ) {
                                                if ( ( $colli_id = Core::get_colli_id_by_colli_uuid($colli_uuid) ) > 0 ) {
                                                        $allowed_moves = Core::get_allowed_store_type_for_colli_id($colli_id);
                                                        $return_data['cid'][] = 'CUR: '.Core::get_last_store_type_for_colli_id( $colli_id ).', allowed: <'.implode(',',$allowed_moves).'>';
                                                        
                                                        if ( $store_type !== false ) {
                                                                $store_type_id = str_replace( 'store_type_','', $store_type);
                                                                if ( in_array($store_type_id,$allowed_moves) ) {
                                                                        $infos[] = "Zeile $row: OK";
                                                                        $count_ok++;
                                                                } else {
                                                                        $errors[] = "Zeile $row: Falsche Buchung f&uuml;r Paket";
                                                                        $count_nok++;
                                                                }
                                                        }
                                                } else {
                                                        $errors[] = "Zeile $row: Paket nicht gefunden";
                                                        $count_nok++;
                                                }
                                        }
                                }
                                if ( $count_ok > 0 && $count_nok == 0 ) {
                                        $return_data['success'] = true;
                                        $return_data['info'] = implode('<br>',$infos);
                                        $return_data['error_text'] = implode('<br>',$errors);
                                } else {
                                        $return_data['success'] = false;
                                        $return_data['info'] = implode('<br>',$infos);
                                        $return_data['error_text'] = implode('<br>',$errors);
                                }
                        }
//                      else {
//                              if ( ( $colli_id = Core::get_colli_id_by_colli_uuid($colli_uuid) ) > 0 ) {
//                                      $allowed_moves = Core::get_allowed_store_type_for_colli_id($colli_id);
//                                      $return_data['cid'] = Core::get_last_store_type_for_colli_id( $colli_id ).'----'.print_r($allowed_moves,1);
//                                      
//                                      if ( $store_type !== false ) {
//                                              $store_type_id = str_replace( 'store_type_','', $store_type);
//                                              if ( in_array($store_type_id,$allowed_moves) ) {
//                                                      $return_data['success'] = true;
//                                              } else {
//                                                      $return_data['error_text'] = "Falsche Buchung f&uuml;r Paket";
//                                                      $return_data['success'] = false;
//                                              }
//                                      }
//                              }
//                      }
                        break;
                case 'check_sector_uuid':
//              echo Core::get_sector_id_by_sector_uuid($sector_uuid);
                        if ( Core::get_sector_id_by_sector_uuid($sector_uuid) > 0 ) {
                                $return_data['success'] = true;
                        }
                        break;
                case 'check_objinfo_uuid':
                        if ( Core::get_object_id_by_object_uuid($objinfo_uuid) > 0 ) {
                                $return_data['success'] = true;
                        } else {
                                $return_data['error_text'] = 'Objekt wurde nicht gefunden (' . $objinfo_uuid . ')';
                                $return_data['success'] = false;
                        }
                        break;
                case 'summary':
                case 'summary_objinfo':
                        $text = array();
                        
                        if ( $store_type !== false ) {
                                $store_type_name = 'unbekannt';
                                foreach ( Core::get_store_types() AS $cur_type ) {
                                        if ( $store_type == 'store_type_' . $cur_type['id'] ) {
                                                $store_type_name = $cur_type['name'];
                                                break;
                                        }
                                }
                                $text[] = 'ausgew&auml;hlter Vorgang: ' . $store_type_name;
                        } elseif ( $additional_type !== false ) {
                                $additional_type_name = 'unbekannt';
                                foreach ( Core::get_additional_selection() AS $cur_type ) {
                                        if ( $additional_type == 'additional_type_' . $cur_type['id'] ) {
                                                $additional_type_name = $cur_type['name'];
                                                break;
                                        }
                                }
                                $text[] = 'ausgew&auml;hlter Vorgang: ' . $additional_type_name;
                        }
                        
//                      if ( $colli_uuid !== false ) {
//                              $text[] = 'Colli UUID: ' . $colli_uuid;
//                              $text[] = 'Colli ID: ' . Core::get_colli_id_by_colli_uuid($colli_uuid);
//                      }
                        
                        if ( Core::array_has_content($colli_uuids) ) {
                                foreach( $colli_uuids AS $colli_uuid ) {
                                        $text[] = 'Colli UUID: ' . $colli_uuid;
                                        $text[] = 'Colli ID: ' . Core::get_colli_id_by_colli_uuid($colli_uuid);
                                }
                        }
                        
                        if ( $sector_uuid !== false ) {
                                $text[] = 'Sector UUID: ' . $sector_uuid;
                                $text[] = 'Sector ID: ' . Core::get_sector_id_by_sector_uuid($sector_uuid);
                                if ( Core::array_has_content($colli_uuids) ) {
                                        foreach( $colli_uuids AS $colli_uuid ) {
                                                $text[] = 'Projekt: ' . Core::get_projekte_id_by_colli_uuid($colli_uuid);
                                        }
                                }
                        }
                        
                        if ( $objinfo_uuid !== false ) {
//                              $text[] = 'Objekt-Info zu UUID: ' . $objinfo_uuid;
                                if ( ( $obj_data = $db->get_object_data_by_object_uuid( $objinfo_uuid ) ) !== false ) {
//                                      $text[] = 'Object: ' . $obj_data['projekte_objektliste_id'];
                                        $text[] = 'Lender: ' . utf8_decode($obj_data['projekte_objektliste_lender']);
                                        $text[] = 'Artist: ' . utf8_decode($obj_data['projekte_objektliste_artist']);
                                        $text[] = 'Title: ' . utf8_decode($obj_data['projekte_objektliste_title']);
                                        $text[] = 'Inv.No.: ' . utf8_decode($obj_data['projekte_objektliste_inv_nr']);
                                        $text[] = 'Project No: ' . utf8_decode($obj_data['projekte_projektnummer']);
                                        $text[] = 'Project Name: ' . utf8_decode($obj_data['projekte_name']);
                                }
                        }
                        
                        $return_data['success'] = true;
                        $return_data['text'] = ( ( Core::array_has_content($text) ) ?  implode ( '<br>' , $text ) : '' );
                        break;
                        
                case 'show_result':
                        if ( ( $store_type !== false ) && ( Core::array_has_content($colli_uuids) ) && ( $sector_uuid !== false ) ) {
                                $store_type_name = 'unbekannt';
                                foreach ( Core::get_store_types() AS $cur_type ) {
                                        if ( $store_type == 'store_type_' . $cur_type['id'] ) {
                                                $store_type_name = $cur_type['name'];
                                                break;
                                        }
                                }
                                $text = 'Bitte Daten &uuml;berpr&uuml;fen und best&auml;tigen!';
                                
                                $return_data['success'] = true;
                                $return_data['text'] = $text;
                        }
                        break;
                        
                case 'submit':
                        if ( ( $store_type !== false ) && ( Core::array_has_content($colli_uuids) ) && ( $sector_uuid !== false ) ) {
                                $success = false;
                                $store_type_id = false;
                                $store_type_name = 'unbekannt';
                                foreach ( Core::get_store_types() AS $cur_type ) {
                                        if ( $store_type == 'store_type_' . $cur_type['id'] ) {
                                                $store_type_id = $cur_type['id'];
                                                $store_type_name = $cur_type['name'];
                                                break;
                                        }
                                }
                                foreach( $colli_uuids AS $colli_uuid ) {
                                        $success = Core::save_store_action_prepare ( $store_type_id , $sector_uuid , $colli_uuid );
                                }
                                
                                if ( $success ) {
                                        $text = 'Daten erfolgreich gespeichert!';
                                } else {
                                        $text = 'FEHLER: Konnte Datensatz nicht speichern!';
                                }
                                $return_data['success'] = $success;
                                $return_data['text'] = $text;
                        }
                        break;
        
        }

}

$return_data['collis'] = print_r($colli_uuids,1);

if ( !Core::array_has_content($return_data) ) {
        $return_data['success'] = false;
        $return_data['info'] = 'Fehler bei der &Uuml;bertragung';
        $return_data['error_text'] = 'Fehler bei der &Uuml;bertragung';
}
if ( !array_key_exists('error_text', $return_data) ) {
        $return_data['error_text'] = "";
}

// $return_data['GET'] = $_GET;
// $return_data['POST'] = $_POST;

echo json_encode($return_data);

?>