00001 <?php
00020 include_once('config.php');
00021
00022
00023
00024 if(!include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'model.php')){
00025 perror('<code>zigmoyd.init.mvc.controller</code><br />Failed To Include Project Model from '.ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'model.php');
00026 exit;
00027 }
00028
00029 if(!include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'model.php')){
00030 perror('<code>zigmoyd.init.mvc.controller</code><br />Failed To Include Project Model from '.ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'model.php');
00031 exit;
00032 }
00033
00034
00035 if(file_exists(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.'scaffold'.DRS.$controllerName.'.php')){
00036 if(!include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.'scaffold'.DRS.$controllerName.'.php')){
00037 perror('<code>zigmoyd.init.mvc.scaffold.controllerLevel</code><br />The Scaffold (Controller Level) Script exists But Zigmoyd failed to include It<br />Plese Check Wheather or Not you have read permission');
00038 exit;
00039 }
00040 }else{
00041 if(file_exists(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'scaffold.php')){
00042 if(!include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'scaffold.php')){
00043 perror('<code>zigmoyd.init.mvc.scaffold.projectLevel</code><br />Failed To Include Project Scaffold (Project Level)<br />Plese Check the File Permission');
00044 }
00045 }else{
00046 perror('<code>zigmoyd.init.mvc.scaffold.projectLevel</code><br />Failed To Include Project Scaffold (Project Level)<br />Project Level Scaffold Doesn\'t exists');
00047 }
00048 }
00049
00050
00051 if(!include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'controller.php')){
00052 perror('<code>zigmoyd.init.mvc.controller</code><br />Failed To Include Project Controller from '.ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'controller.php');
00053 exit;
00054 }
00055
00056
00057
00058 if(!include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'zOrmRow.php')){
00059 perror('Failed to Include the Project Level RowSet');
00060 }
00061 if(!include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_LOCAL_SRC.DRS.'zOrmTable.php')){
00062 perror('Failed to Include the Project Level Table set');
00063 }
00064
00065
00066
00067 $accessData = vldMapParser::tokenize(Z_PROJECT_NAME.'.access'.DRS.'global.access.map.php', true);
00068 if(!file_exists(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.ZIGSETTINGSDIR.DRS.Z_DIR_ETC_CONF.DRS."access".DRS.$controllerName.".access.map.php")){
00069 zLogger::debug("Access Specifier Map has not been parsed as it does not exist", "mvc.access");
00070 }else{
00071 zLogger::debug("Access Specifier Map has been parsed", "mvc.access");
00072 foreach(vldMapParser::tokenize(Z_PROJECT_NAME.'.access'.DRS.$controllerName.'.access.map.php', true) as $key => $val){
00073 $accessData[$key] = $val;
00074 }
00075 }
00076 if(!isset($accessData[$methodName]) || (isset($accessData[$methodName]) && !isset($accessData[$methodName]['access']))){
00077 zLogger::debug("Requested method $methodName of $controllerName"." Controller does not have any access Specifier (Assumed as (default)public)", "mvc.access");
00078 $accessPermited = true;
00079 }else{
00080 zLogger::debug("Requested method $methodName of $controllerName"." Controller is ".$accessData[$methodName]['access'], "mvc.access");
00081 switch($accessData[$methodName]['access']){
00082 case 'public':
00083 $accessPermited = true;
00084 break;
00085 case 'private':
00086 $accessPermited = false;
00087 break;
00088 case 'protected':
00089 $protectedData = $accessData[$methodName];
00090 if(!isset($protectedData['mode'])){
00091 perror('<code>zigmoyd.app.router</code><br />HTTP Authentication Mode not found for method '.$methodName.'<br />Plese add a mode attribute whose value must be plain/db');
00092 exit;
00093 }
00094 if(!isset($protectedData['usr'])){
00095 perror('<code>zigmoyd.app.router</code><br />HTTP Authentication UserName not found for method '.$methodName.'<br />Plese add a usr attribute');
00096 exit;
00097 }
00098 if(!isset($protectedData['psw'])){
00099 perror('<code>zigmoyd.app.router</code><br />HTTP Authentication Password not found for method '.$methodName.'<br />Plese add a psw attribute');
00100 exit;
00101 }
00102 if($protectedData['mode'] == 'db'){
00103 if(!isset($protectedData['con'])){
00104 perror('<code>zigmoyd.app.router</code><br />HTTP Authentication connection not found for method '.$methodName.'<br />Plese add a con attribute');
00105 exit;
00106 }
00107 if(!isset($protectedData['table'])){
00108 perror('<code>zigmoyd.app.router</code><br />HTTP Authentication Table not found for method '.$methodName.'<br />Plese add a table attribute');
00109 exit;
00110 }
00111 }
00112 $accessPermited = true;
00113 break;
00114 default:
00115 perror('<code>zigmoyd.app.router</code><br />Invalid Access Specifier '.$accessData[$methodName]['access'].' for method '.$methodName);
00116 exit;
00117 }
00118 }
00119 unset($accessData);
00120 if(!$accessPermited){
00121 perror('<code>zigmoyd.mvc.access</code><br />You dont have Privileges to access this Page');
00122 }else{
00123
00124
00125 $controllerFile = ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.Z_PROJECT_DIR.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.'.php';
00126 if(!file_exists($controllerFile)){
00127 exit(zTemplate::sysNumeric('c404', $controllerFile, $controllerName, $controllerName, $projectName));
00128 }elseif(!is_readable($controllerFile)){
00129 exit(zTemplate::sysNumeric('c403', $controllerFile));
00130 }else{
00131 if(!@include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.'.php')){
00132 perror('failed to include the file that holds the '.$controllerName.' Class as the file '.ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.'.controller.php'.' doesn\'t exists');
00133 }
00134
00135
00136 if(is_dir(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName)){
00137 zLogger::debug("detected Directory with the same name of the Controller", "mvc.multiFile");
00138 if(file_exists(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.DRS.$methodName.'.php')){
00139 if(is_readable(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.DRS.$methodName.'.php')){
00140 zLogger::debug("including Multifile Controller form $controllerName class's $methodName method", 'mvc.multiFile');
00141 include_once(ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.DRS.$methodName.'.php');
00142 $class_name = $controllerName.'Sibling';
00143 $controllerFile = dirname($controllerFile).DRS.$controllerName.DRS."$methodName.php";
00144 $controllerTemplate = 'c500m';
00145 $methodtemplate = 'cm404m';
00146 }else{
00147 zLogger::error("expecting ".ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.DRS.$methodName.'.php'." file as The Directory with same name as the controller means you are utilizing the Multi file Controller Feature But the file is not readable", 'mvc.multiFile');
00148 perror("<code>zigmoyd.mvc.multiFile</code><br />expecting ".ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.DRS.$methodName.'.php'." file as The Directory with same name as the controller means you are utilizing the Multi file Controller Feature But the file is not readable");
00149 exit;
00150 }
00151 }else{
00152 zLogger::debug("expecting ".ZIGROOT.DRS.Z_DIR_PROJECTS.DRS.$projectDir.DRS.Z_DIR_APPS.DRS.Z_DIR_MVC_CONTROLLER.DRS.$controllerName.DRS.$methodName.'.php'." file as The Directory with same name as the controller means you are utilizing the Multi file Controller Feature But the file doesn't exist so thinking that this method is a regular method of $controllerName"."Controller Class", 'mvc.multiFile');
00153
00154 $class_name = $controllerName.'Controller';
00155
00156 $controllerTemplate = 'c500';
00157 $methodtemplate = 'cm404';
00158 }
00159 }else{
00160 $class_name = $controllerName.'Controller';
00161 $controllerTemplate = 'c500';
00162 $methodtemplate = 'cm404';
00163 }
00164
00165 if(!class_exists($class_name)){
00166 exit(zTemplate::sysNumeric($controllerTemplate, $controllerFile, $controllerName, $controllerName, $projectName));
00167 }else{
00168 $mvc = new $class_name;
00169
00170 if(isset($protectedData)){
00171 load_module('httpAuth');
00172 $httpAuth = new zHttpAuth($mvc);
00173 switch($protectedData['mode']){
00174 case 'plain':
00175 $httpAuth->setRawCredentials($protectedData['usr'], $protectedData['psw']);
00176 break;
00177 case 'db':
00178 $httpAuth->setCredentialsDataCon($protectedData['con']);
00179 $httpAuth->setCredentialsDataCol($protectedData['table'], $protectedData['usr'], $protectedData['psw']);
00180 break;
00181 default:
00182 perror('<code>zigmoyd.app.router</code><br />Invalid HTTP Authentication Mode '.$accessData[$methodName]['mode'].' for method '.$methodName);
00183 exit;
00184 }
00185 if(!$httpAuth->isOk()){
00186 $httpAuth->loop();
00187 }
00188 }
00189
00190 if(method_exists($mvc, $methodName)){
00191 $mvc->attachModel($controllerName, $projectName);
00192 if(method_exists($mvc, 'init'))$mvc->init($projectName, $controllerName, $methodName, $args);
00193 call_user_func_array(array(&$mvc, $methodName), $args);
00194 if(!$mvc->noAutoViewRender)$mvc->renderView($methodName);
00195 call_user_func(array(&$mvc, 'commitViews'));
00196 }else{
00197 exit(zTemplate::sysNumeric($methodtemplate, $methodName, $class_name, $controllerFile, $controllerName, $projectName));
00198 }
00199 }
00200 }
00201 }
00202 zLogger::debug("Application Served $projectName.$controllerName/$methodName/".implode('/', $args), 'zigmoyd.logger.end');
00203 ?>