如果你把这个代码丢在你的腿上,你会怎么做?

时间:2009-06-18 04:46:09

标签: php

伙计,我刚刚把这个项目交给了我 - 他们说这个就扩展了。

这是ONE功能的一个例子:

<?php


//500+ lines of pure wonder.
function page_content_vc($content) {
    global $_DBH, $_TPL, $_SET;

 $_SET['ignoreTimezone'] = true;

    lu_CheckUpdateLogin();

    if($_SESSION['dash']['VC']['switch'] == 'unmanned' || $_SESSION['dash']['VC']['switch'] == 'touchscreen') {
        if($content['page_name'] != 'vc') {
            header('Location: /vc/');
            die();
        }
    }

    if($_GET['l']) {
        unset($_SESSION['dash']['VC']);
        if($loc_id = lu_GetFieldValue('ID', 'Location', $_GET['l'])) {

            if(lu_CheckPermissions('vc', $loc_id)) {

    $timezone = lu_GetFieldValue('Time Zone', 'Location', $loc_id, 'ID');
    if(strlen($timezone) > 0) {
     $_SESSION['time_zone'] = $timezone;
    }

                $_SESSION['dash']['VC']['loc_ID'] = $loc_id;
                header('Location: /vc/');
                die();
            }
        }
    }

    if($_SESSION['dash']['VC']['loc_ID']) {

  $timezone = lu_GetFieldValue('Time Zone', 'Location', $_SESSION['dash']['VC']['loc_ID'], 'ID');
  if(strlen($timezone) > 0) {
   $_SESSION['time_zone'] = $timezone;
  }

        $loc_id = $_SESSION['dash']['VC']['loc_ID'];
        $org_id = lu_GetFieldValue('record_ID', 'Location', $loc_id);

        $_TPL->assign('loc_id', $loc_id);

        $location_name = lu_GetFieldValue('Location Name', 'Location', $loc_id);
        $_TPL->assign('LocationName', $location_name);

        $customer_name = lu_GetFieldValue('Customer Name', 'Organisation', $org_id);
        $_TPL->assign('CustomerName', $customer_name);

        $enable_visitor_snap = lu_GetFieldValue('VisitorSnap', 'Location', $loc_id);
        $_TPL->assign('EnableVisitorSnap', $enable_visitor_snap);

  $lacps = explode("\n", lu_GetFieldValue('Location Access Control Point', 'Location', $loc_id));
        array_walk($lacps, 'trim_value');

  if(count($lacps) > 0) {
   if(count($lacps) == 1) {
    $_SESSION['dash']['VC']['lacp'] = $lacps[0];
   }
   else {
    if($_GET['changeLACP'] && in_array($_GET['changeLACP'], $lacps)) {
     $_SESSION['dash']['VC']['lacp'] = $_GET['changeLACP'];
     header('Location: /vc/');
     die();
    }
    else if(!in_array($_SESSION['dash']['VC']['lacp'], $lacps)) {
     $_SESSION['dash']['VC']['lacp'] = $lacps[0];
    }
    $_TPL->assign('LACP_array', $lacps);
   }
   $_TPL->assign('current_LACP', $_SESSION['dash']['VC']['lacp']);
   $_TPL->assign('showContractorSearch', true);
   /*
   if($contractorStaff = lu_GetTableRow('ContractorStaff', $org_id, 'record_ID', 'record_Inactive != "checked"')) {
    foreach($contractorStaff['rows'] as $contractor) {
     $lacp_rights = lu_OrganiseCustomDataFunctionMultiselect($contractor[lu_GetFieldName('Location Access Rights', 'ContractorStaff')]);
     if(in_array($_SESSION['dash']['VC']['lacp'], $lacp_rights)) {
      $_TPL->assign('showContractorSearch', true);
     }
    }
   }
   */
  }

  $selectedOptions = explode(',', lu_GetFieldValue('Included Fields', 'Location', $_SESSION['dash']['VC']['loc_ID']));
  $newOptions = array();
  foreach($selectedOptions as $selOption) {
   $so_array = explode('|', $selOption, 2);
   if(count($so_array) > 1) {
    $newOptions[$so_array[0]] = $so_array[1];
   }
   else {
    $newOptions[$so_array[0]] = "Both";
   }
  }  

  if($newOptions[lu_GetFieldName('Expected Length of Visit', 'Visitor')]) {

   $alert = false;

            if($visitors = lu_OrganiseVisitors(
                lu_GetTableRow('Visitor', 'checked',
                    lu_GetFieldName('Checked In', 'Visitor'),
                    lu_GetFieldName('Location for Visit', 'Visitor').'="'.$_SESSION['dash']['VC']['loc_ID'].'"
                    AND '.lu_GetFieldName('Checked Out', 'Visitor').' != "checked"'), false, true, true)) {

                foreach($visitors['rows'] as $key => $visitor) {
     if($visitor['expected'] && $visitor['expected'] + (60*30) < time()) {
      $alert = true;
     }
                }
            }
   if($alert == true) {
    $_TPL->assign('showAlert', 'red');
   }
   else {
    //$_TPL->assign('showAlert', 'green');
   }
  }


        $_TPL->assign('switch', $_SESSION['dash']['VC']['switch']);
  if($_SESSION['dash']['VC']['switch'] == 'touchscreen') {
   $_TPL->assign('VC_unmanned', true);
  }

        if($_GET['check'] == 'in') {
   if($_SESSION['dash']['VC']['switch'] == 'touchscreen') {
    lu_CheckInTouchScreen();
            }
   else {
    lu_CheckIn();
   }
        }
        else if($_GET['check'] == 'out') {
   if($_SESSION['dash']['VC']['switch'] == 'touchscreen') {
    lu_CheckOutTouchScreen();
            }
   else {
    lu_CheckOut();
   }
        }
        else if($_GET['switch'] == 'unmanned') {
            $_SESSION['dash']['VC']['switch'] = 'unmanned';
            if($_GET['printing'] == true && (lu_GetFieldValue('Printing', 'Location', $_SESSION['dash']['VC']['loc_ID']) != "No" && lu_GetFieldValue('Printing', 'Location', $_SESSION['dash']['VC']['loc_ID']) != "")) {
                $_SESSION['dash']['VC']['printing'] = true;
            }
            else {
                $_SESSION['dash']['VC']['printing'] = false;
            }
            header('Location: /vc/');
            die();
        }
        else if($_GET['switch'] == 'touchscreen') {
            $_SESSION['dash']['VC']['switch'] = 'touchscreen';
            if($_GET['printing'] == true && (lu_GetFieldValue('Printing', 'Location', $_SESSION['dash']['VC']['loc_ID']) != "No" && lu_GetFieldValue('Printing', 'Location', $_SESSION['dash']['VC']['loc_ID']) != "")) {
                $_SESSION['dash']['VC']['printing'] = true;
            }
            else {
                $_SESSION['dash']['VC']['printing'] = false;
            }
            header('Location: /vc/');
            die();
        }

        else if($_GET['switch'] == 'manned') {
            if($_POST['password']) {
                if(md5($_POST['password']) == $_SESSION['dash']['password']) {
                    unset($_SESSION['dash']['VC']['switch']);
                    //setcookie('email', "", time() - 3600);
                    //setcookie('location', "", time() - 3600);
                    header('Location: /vc/');
                    die();
                }
                else {
                    $_TPL->assign('switchLoginError', 'Incorrect Password');
                }
            }

            $_TPL->assign('switchLogin', 'true');
        }
        else if($_GET['m'] == 'visitor') {
            lu_ModifyVisitorVC();
        }

        else if($_GET['m'] == 'enote') {
            lu_ModifyEnoteVC();
        }

        else if($_GET['m'] == 'medical') {
            lu_ModifyMedicalVC();
        }

        else if($_GET['print'] == 'label' && $_GET['v']) {
            lu_PrintLabelVC();
        }

        else {
            unset($_SESSION['dash']['VC']['checkin']);
            unset($_SESSION['dash']['VC']['checkout']);

            $_TPL->assign('icon', 'GroupCheckin');

            if($_SESSION['dash']['VC']['switch'] != 'unmanned' && $_SESSION['dash']['VC']['switch'] != 'touchscreen') {

                $staff_ids = array();
                if($staffs = lu_GetTableRow('Staff', $_SESSION['dash']['VC']['loc_ID'], 'record_ID')) {
                    foreach($staffs['rows'] as $staff) {
                        $staff_ids[] = $staff['ID'];
                    }
                }

                if($_GET['view'] == "tomorrow") {
                    $dateStart = date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
                    $dateEnd = date('Y-m-d', mktime(0, 0, 0, date("m")  , date("d")+1, date("Y")));
                }
                else if($_GET['view'] == "month") {
                    $dateStart = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d"), date("Y")));
                    $dateEnd = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+30, date("Y")));
                }
                else if($_GET['view'] == "week") {
                    $dateStart = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d"), date("Y")));
                    $dateEnd = date('Y-m-d', mktime(0, 0, 0, date("m"), date("d")+7, date("Y")));
                }
                else {
                    $dateStart = date('Y-m-d');
                    $dateEnd = date('Y-m-d');
                }

    if(lu_GetFieldValue('Enable Survey', 'Location', $_SESSION['dash']['VC']['loc_ID']) == 'checked'
     && lu_GetFieldValue('Add Survey', 'Location', $_SESSION['dash']['VC']['loc_ID']) == 'checked') {
      $_TPL->assign('enableSurvey', true);
    }

                //lu_GetFieldName('Checked In', 'Visitor')
                //!= "checked"

                //date('d/m/Y'), lu_GetFieldName('Date of Visit', 'Visitor')

                if($visitors = lu_OrganiseVisitors(lu_GetTableRow('Visitor', $_SESSION['dash']['VC']['loc_ID'], lu_GetFieldName('Location for Visit', 'Visitor'), lu_GetFieldName('Checked In', 'Visitor').' != "checked" AND '.lu_GetFieldName('Checked Out', 'Visitor').' != "checked" AND '.lu_GetFieldName('Date of Visit', 'Visitor').' >= "'.$dateStart.'" AND '.lu_GetFieldName('Date of Visit', 'Visitor').' <= "'.$dateEnd.'"'))) {
                    foreach($visitors['days'] as $day => $visitors_day) {
                        foreach($visitors_day['rows'] as $key => $visitor) {
                            $visitors['days'][$day]['rows'][$key]['visiting'] = lu_GetTableRow('Staff', $visitor['record_ID'], 'ID');
                            $visitors['days'][$day]['rows'][$key]['visiting']['notify'] = $_DBH->getRow('SELECT * FROM lu_notification WHERE ent_ID = "'.$visitor['record_ID'].'"');
                        }
                    }

                    //array_dump($visitors);

                    $_TPL->assign('visitors', $visitors);
                }

    if($_GET['conGroup']) {
     if($_GET['action'] == 'add') {
      $_SESSION['dash']['VC']['conGroup'][$_GET['conGroup']] = $_GET['conGroup'];
     }
     else {
      unset($_SESSION['dash']['VC']['conGroup'][$_GET['conGroup']]);
     }
    }

    if(count($_SESSION['dash']['VC']['conGroup']) > 0) {
                    if($conGroupResult = lu_GetTableRow('ContractorStaff', '1', '1', ' ID IN ('.implode(',', $_SESSION['dash']['VC']['conGroup']).')')) {

      if($_POST['_submit'] == 'Check-In Group >>') {

                         $form = lu_GetForm('VisitorStandard');
       $standarddata = array();

       foreach($form['items'] as $key=>$item) {
        $standarddata[$key] = $_POST[lu_GetFieldName($item['name'], 'Visitor')];
       }

       foreach($conGroupResult['rows'] as $conStaff) {
        $data = $standarddata;

        foreach($form['items'] as $key=>$item) {
         if($key != 'ID' && $key != 'record_ID' && $conStaff[lu_GetFieldName(lu_GetNameField($key, 'Visitor'), 'ContractorStaff')]) {
          $data[$key] = $conStaff[lu_GetFieldName(lu_GetNameField($key, 'Visitor'), 'ContractorStaff')];
         }
        }

        $data['record_ID'] = $data[lu_GetFieldName('Visiting', 'Visitor')];
                          $data[lu_GetFieldName('Date of Visit', 'Visitor')] = date('Y-m-d');
                          $data[lu_GetFieldName('Time of Visit', 'Visitor')] = date('H:i');
                          $data[lu_GetFieldName('Checked In', 'Visitor')] = 'checked';
                          $data[lu_GetFieldName('Location for Visit', 'Visitor')] = $_SESSION['dash']['VC']['loc_ID'];
                          $data[lu_GetFieldName('ConStaff ID', 'Visitor')] = $conStaff['ID'];
        $data[lu_GetFieldName('From', 'Visitor')] = lu_GetFieldValue('Legal Name', 'Contractor', $conStaff[lu_GetFieldName('Contractor', 'ContractorStaff')]);

                          $id = lu_UpdateData($form, $data);
                          lu_VisitorCheckIn($id);

        //array_dump($data);
        //array_dump($id);
       }


       unset($_SESSION['dash']['VC']['conGroup']);
       header('Location: /vc/');
       die();
      }

      if(count($conGroupResult['rows'])) {
                         foreach($conGroupResult['rows'] as $key => $cstaff) {
                             $conGroupResult['rows'][$key]['contractor'] = lu_GetTableRow('Contractor', $cstaff[lu_GetFieldName('Contractor', 'ContractorStaff')], 'ID');
                         }
                         $_TPL->assign('conGroupResult', $conGroupResult);
      }

      $conGroupForm = lu_GetForm('VisitorConGroup');
      $conGroupForm = lu_OrganiseVisitorForm($conGroupForm, $_SESSION['dash']['VC']['loc_ID'], 'Contractor');

            $secure_options_array = lu_GetSecureOptions($org_id);
            if($secure_options_array[$_SESSION['dash']['VC']['loc_ID']]) {
             $conGroupForm['items'][lu_GetFieldName('Secure Area', 'Visitor')]['options']['values'] = $secure_options_array[$_SESSION['dash']['VC']['loc_ID']];
       $conGroupForm['items'][lu_GetFieldName('Secure Area', 'Visitor')]['name'] = 'Secure  Area';
      }
      else {
                unset($conGroupForm['items'][lu_GetFieldName('Secure Area', 'Visitor')]);
      }

         if($secure_options_array) {
             $form['items'][lu_GetFieldName('Secure Area', 'Visitor')]['options']['values'] = $secure_options_array;
       $form['items'][lu_GetFieldName('Secure Area', 'Visitor')]['name'] = 'Secure  Area';
         }
         else {
             unset($form['items'][lu_GetFieldName('Secure Area', 'Visitor')]);
         }

         $_TPL->assign('conGroupForm', $conGroupForm);
      $_TPL->assign('hideFormCancel', true);
     }
    }

                if($_GET['searchVisitors']) {
                    $_TPL->assign('searchVisitorsQuery', $_GET['searchVisitors']);
                    $where = '';

                    if($_GET['searchVisitorsIn'] == 'Yes') {
                        $where .= ' AND '.lu_GetFieldName('Checked In', 'Visitor').' = "checked"';
                        $_TPL->assign('searchVisitorsIn', 'Yes');
                    }
                    else {
                        $where .= ' AND '.lu_GetFieldName('Checked In', 'Visitor').' != "checked"';
                        $_TPL->assign('searchVisitorsIn', 'No');
                    }

                    if($_GET['searchVisitorsOut'] == 'Yes') {
                        $where = '';
                        $where .= ' AND '.lu_GetFieldName('Checked Out', 'Visitor').' = "checked"';
                        $_TPL->assign('searchVisitorsOut', 'Yes');
                    }
                    else {
                        $where .= ' AND '.lu_GetFieldName('Checked Out', 'Visitor').' != "checked"';
                        $_TPL->assign('searchVisitorsOut', 'No');
                    }

                    if($searchVisitors = lu_OrganiseVisitors(lu_GetTableRow('Visitor', $_GET['searchVisitors'], '#search#', lu_GetFieldName('Location for Visit', 'Visitor').'="'.$_SESSION['dash']['VC']['loc_ID'].'"'.$where))) {
                        foreach($searchVisitors['rows'] as $key => $visitor) {
                            $searchVisitors['rows'][$key]['visiting'] = lu_GetTableRow('Staff', $visitor['record_ID'], 'ID');
                        }

                        $_TPL->assign('searchVisitors', $searchVisitors);
                    }
                    else {
                        $_TPL->assign('searchVisitorsNotFound', true);
                    }
                }
                else if($_GET['searchStaff']) {

                    if($_POST['staff_id']) {
                        if(lu_CheckPermissions('staff', $_POST['staff_id'])) {
                            $_DBH->query('UPDATE '.lu_GetTableName('Staff').' SET '.lu_GetFieldName('Current Location', 'Staff').' = "'.$_POST['current_location'].'" WHERE ID="'.$_POST['staff_id'].'"');
                        }
                    }


                    $locations = lu_GetTableRow('Location', $org_id, 'record_ID');

                    if(count($locations['rows']) > 1) {
                        $_TPL->assign('staffLocations', $locations);
                    }

                    $loc_ids = array();
                    foreach($locations['rows'] as $location) {
                        $loc_ids[] = $location['ID'];
                    }

                    // array_dump($locations);
                    // array_dump($_POST);

                    $_TPL->assign('searchStaffQuery', $_GET['searchStaff']);
                    $where = ' AND record_Inactive != "checked"';

                    if($_GET['searchStaffIn'] == 'Yes' && $_GET['searchStaffOut'] != 'Yes') {
                        $where .= ' AND ('.lu_GetFieldName('Staff Status', 'Staff').' = "" OR '.lu_GetFieldName('Staff Status', 'Staff').' = "On-Site")'.

                        $_TPL->assign('searchStaffIn', 'Yes');
                        $_TPL->assign('searchStaffOut', 'No');
                    }
                    else if($_GET['searchStaffOut'] == 'Yes' && $_GET['searchStaffIn'] != 'Yes') {
                        $where .= ' AND ('.lu_GetFieldName('Staff Status', 'Staff').' != "" AND '.lu_GetFieldName('Staff Status', 'Staff').' != "On-Site")'.
                        $_TPL->assign('searchStaffOut', 'Yes');
                        $_TPL->assign('searchStaffIn', 'No');
                    }
                    else {
                        $_TPL->assign('searchStaffOut', 'Yes');
                        $_TPL->assign('searchStaffIn', 'Yes');
                    }

                    if($searchStaffs = lu_GetTableRow('Staff', $_GET['searchStaff'], '#search#', 'record_ID IN ('.implode(',', $loc_ids).')'.$where, lu_GetFieldName('First Name', 'Staff').','.lu_GetFieldName('Surname', 'Staff'))) {
                        $_TPL->assign('searchStaffs', $searchStaffs);
                    }
                    else {
                        $_TPL->assign('searchStaffNotFound', true);
                    }
                }
    else if($_GET['searchContractor']) {

                    $_TPL->assign('searchContractorQuery', $_GET['searchContractor']);
                    //$where = ' AND '.lu_GetTableName('ContractorStaff').'.record_Inactive != "checked"';
     $where = ' ';

                    if($_GET['searchContractorIn'] == 'Yes' && $_GET['searchContractorOut'] != 'Yes') {
                        $where .= ' AND ('.lu_GetFieldName('Onsite Status', 'ContractorStaff').' = "Onsite")';

                        $_TPL->assign('searchContractorIn', 'Yes');
                        $_TPL->assign('searchContractorOut', 'No');
                    }
                    else if($_GET['searchContractorOut'] == 'Yes' && $_GET['searchContractorIn'] != 'Yes') {
                        $where .= ' AND ('.lu_GetFieldName('Onsite Status', 'ContractorStaff').' != "Onsite")'.
                        $_TPL->assign('searchContractorOut', 'Yes');
                        $_TPL->assign('searchContractorIn', 'No');
                    }
                    else {
                        $_TPL->assign('searchContractorOut', 'Yes');
                        $_TPL->assign('searchContractorIn', 'Yes');
                    }

     $join = 'LEFT JOIN '.lu_GetTableName('Contractor').' ON '.lu_GetTableName('Contractor').'.ID = '.lu_GetTableName('ContractorStaff').'.'.lu_GetFieldName('Contractor', 'ContractorStaff');

     $extrasearch = array (
      lu_GetTableName('Contractor').'.'.lu_GetFieldName('Legal Name', 'Contractor')
     );

                    if($searchContractorResult = lu_GetTableRow('ContractorStaff', $_GET['searchContractor'], '#search#', lu_GetTableName('ContractorStaff').'.record_ID = "'.$org_id.'" '.$where, lu_GetFieldName('First Name', 'ContractorStaff').','.lu_GetFieldName('Surname', 'ContractorStaff'), $join, $extrasearch)) {

      /*
      foreach($searchContractorResult['rows'] as $key=>$contractor) {
       $lacp_rights = lu_OrganiseCustomDataFunctionMultiselect($contractor[lu_GetFieldName('Location Access Rights', 'ContractorStaff')]);
       if(!in_array($_SESSION['dash']['VC']['lacp'], $lacp_rights)) {
        unset($searchContractorResult['rows'][$key]);
       }
      }
      */

      if(count($searchContractorResult['rows'])) {
                         foreach($searchContractorResult['rows'] as $key => $cstaff) {
        /*
        if($cstaff[lu_GetFieldName('Onsite_Status', 'Contractor')] == 'Onsite')) {
         if($visitor['rows'][0][lu_GetFieldName('ConStaff ID', 'Visitor')]) {
                   $_DBH->query('UPDATE '.lu_GetTableName('ContractorStaff').' SET '.lu_GetFieldName('Onsite Status', 'ContractorStaff').' = "" WHERE ID="'.$visitor['rows'][0][lu_GetFieldName('ConStaff ID', 'Visitor')].'"');
         }
        }
        */
        if($cstaff[lu_GetFieldName('SACN Expiry Date', 'ContractorStaff')] != '0000-00-00') {
         if(strtotime($cstaff[lu_GetFieldName('SACN Expiry Date', 'ContractorStaff')]) < time()) {
          $searchContractorResult['rows'][$key]['sacn_expiry'] = true;
         }
         else {
          $searchContractorResult['rows'][$key]['sacn_expiry'] = false;
         }
        }
        else {
         $searchContractorResult['rows'][$key]['sacn_expiry'] = false;
        }

        if($cstaff[lu_GetFieldName('Induction Valid Until', 'ContractorStaff')] != '0000-00-00') {
         if(strtotime($cstaff[lu_GetFieldName('Induction Valid Until', 'ContractorStaff')]) < time()) {
          $searchContractorResult['rows'][$key]['induction_expiry'] = true;
         }
         else {
          $searchContractorResult['rows'][$key]['induction_expiry'] = false;
         }
        }
        else {
         $searchContractorResult['rows'][$key]['induction_expiry'] = false;
        }

                             $searchContractorResult['rows'][$key]['contractor'] = lu_GetTableRow('Contractor', $cstaff[lu_GetFieldName('Contractor', 'ContractorStaff')], 'ID');
                         }
                         $_TPL->assign('searchContractorResult', $searchContractorResult);
      }
      else {
                         $_TPL->assign('searchContractorNotFound', true);
      }
                    }
                    else {
                        $_TPL->assign('searchContractorNotFound', true);
                    }
    }

                $occupancy = array();
                $occupancy['staffNumber'] = $_DBH->getOne('SELECT count(*) FROM '.lu_GetTableName('Staff').' WHERE record_ID = "'.$_SESSION['dash']['VC']['loc_ID'].'" AND record_Inactive != "checked" AND '.lu_GetFieldName('Ignore Counts', 'Staff').' != "checked"');
                $occupancy['staffNumberOnsite']= $_DBH->getOne(
                        'SELECT count(*) FROM '.lu_GetTableName('Staff').' WHERE
                        (
                            (record_ID = "'.$_SESSION['dash']['VC']['loc_ID'].'"
                                AND
                                ('.lu_GetFieldName('Staff Status', 'Staff').' = "" OR  '.lu_GetFieldName('Staff Status', 'Staff').' = "On-Site"))
                                OR '.lu_GetFieldName('Current Location', 'Staff').' = "'.$_SESSION['dash']['VC']['loc_ID'].'")
                                AND record_Inactive != "checked"
        AND '.lu_GetFieldName('Ignore Counts', 'Staff').' != "checked"');

                $occupancy['visitorsOnsite'] = $_DBH->getOne('SELECT count(*) FROM '.lu_GetTableName('Visitor').' WHERE '.lu_GetFieldName('Location for Visit', 'Visitor').' = "'.$_SESSION['dash']['VC']['loc_ID'].'" AND '.lu_GetFieldName('Checked In', 'Visitor').' = "checked" AND '.lu_GetFieldName('Checked Out', 'Visitor').' != "checked"');
                $_TPL->assign('occupancy', $occupancy);

                if($enotes = lu_GetTableRow('Enote', $org_id, 'record_ID', lu_GetFieldName('Note Emailed', 'Enote').' = "0000-00-00" AND '.lu_GetFieldName('Note Passed On', 'Enote').' != "Yes"')) {
                    $_TPL->assign('EnoteNotice', true);
                }

                if($medical = lu_GetTableRow('MedicalRoom', $_SESSION['dash']['VC']['loc_ID'], 'record_ID', 'record_Inactive != "Yes"')) {
                    $_TPL->assign('MedicalNotice', true);
                }

                if(lu_GetFieldValue('Printing', 'Location', $_SESSION['dash']['VC']['loc_ID']) != "No" && lu_GetFieldValue('Printing', 'Location', $_SESSION['dash']['VC']['loc_ID']) != "") {
                    $_TPL->assign('UnmannedPrinting', true);
                }
            }
            else {
                if($_SESSION['dash']['VC']['printing'] == true) {
                    $_TPL->assign('UnmannedPrinting', true);
                }
            }

   // enable if contractor check-in buttons should be enabled
            if(lu_GetFieldValue('Enable Contractor Check In', 'Location', $_SESSION['dash']['VC']['loc_ID']) == "checked") {
                $_TPL->assign('ContractorCheckin', true);
            }

        }


  if($_SESSION['dash']['entity_id'] && $_GET['fixupCon'] == 'true') {
         $conStaffs = lu_GetTableRow('ContractorStaff', $_SESSION['dash']['ModifyConStaffs']['org_ID'], 'record_ID', '', lu_GetFieldName('First Name', 'ContractorStaff').','.lu_GetFieldName('Surname', 'ContractorStaff'));
      foreach($conStaffs['rows'] as $key => $cstaff) {
    if($cstaff[lu_GetFieldName('Site Access Card Number', 'ContractorStaff')] && $cstaff[lu_GetFieldName('Site Access Card Type', 'ContractorStaff')]) {
     echo $cstaff['ID'].' ';
     $_DBH->query('UPDATE '.lu_GetTableName('Visitor').' SET '.lu_GetFieldName('Site Access Card Number', 'Visitor').' = "'.$cstaff[lu_GetFieldName('Site Access Card Number', 'ContractorStaff')].'", '.lu_GetFieldName('Site Access Card Type', 'Visitor').' = "'.$cstaff[lu_GetFieldName('Site Access Card Type', 'ContractorStaff')].'" WHERE '.lu_GetFieldName('ConStaff ID', 'Visitor').'="'.$cstaff['ID'].'"');
    }
      }
  }

    }
    else {
        if($_SESSION['dash']['staffs']) {
            foreach($_SESSION['dash']['staffs']['rows'] as $staff) {
                if($staff[lu_GetFieldName('Reception Manager', 'Staff')] == 'checked') {
                    $loc_id = $staff['record_ID'];
                    unset($_SESSION['dash']['VC']);
                    if($loc_id = lu_GetFieldValue('ID', 'Location', $loc_id)) {
                        $_SESSION['dash']['VC']['loc_ID'] = $loc_id;
                        header('Location: /vc/');
                        die();
                    }
                }
            }
        }

        $_TPL->assign('mode', 'public');
    }

    $content['page_content'] = $_TPL->fetch('modules/vc.htm');
    return $content;
}


?>

这个问题可能会被关闭 - 我只需要我编码兄弟姐妹的支持。 * * SOB

14 个答案:

答案 0 :(得分:25)

全球搜索和替换是您的朋友。

开始于:

  1. 将巨大的“if ... else”分解为单个函数,一旦你弄清楚它们的作用,你可以稍后重命名。
  2. 对$ _GET [...]和$ _SESSION ['dash']变量进行全局搜索/替换,为其提供更有意义的名称
  3. 继续清理
  4. 简而言之,使用基本的计算机编程技术:分而治之。将功能划分为较小的部分,然后清理各个部分。不应该超过一个小时。

答案 1 :(得分:9)

软件是一项业务。

你已经交了基本上不可维护的代码,并被要求用它做一些事情。这将需要大量重构。

坏消息是吮吸

好消息是,为了换取您的时间,公司将为您提供金钱,您将可以换取商品和服务,例如食品,衣服,啤酒和音乐会门票。

只要每个人都对所涉及的时间成本有正确或至少近似的理解,你应该没事。

答案 2 :(得分:5)

我会告诉那些倾向于我的项目,如果他们想对网站做任何事情,就必须重新写一遍。 (这个建议不保证不会让你被解雇。)

答案 3 :(得分:5)

相信我,我看到了更糟糕的代码。正如其他人所说,应用一些重构。

我通常的攻击计划:

  • 如果代码没有与系统中的其他所有内容紧密耦合,请编写大量的单元测试。这些将帮助您确保重构代码的行为没有改变。
  • 尽可能多地提取功能,除以逻辑运算。即使这意味着某些功能将包含两行代码。
  • 内联您创建的200种方法中的一些:)

推荐阅读:

alt text
(来源:martinfowler.com

答案 4 :(得分:3)

我继承这样的代码的正常回应是追踪原始开发人员的家庭地址,作为一种只是在案例中我需要的东西。

答案 5 :(得分:3)

坚持下去。我知道你的感受。

答案 6 :(得分:3)

坚强,我的朋友。

确实是丑陋的代码,但不可能是不可读的。

除了早先陈述的替换策略(我也建议)之外,我的建议是记录函数中发生的事情,因为你更了解它 - 这可以在代码中的临时注释中,在单独的文本文件,或在一张纸上。重要的是,如果您需要长时间休息或周末到来,您可以参考。令人讨厌的代码带来了思想想要忘记它的习惯 - 确保你的发现备份。

另一个建议是,考虑到你的示例函数的长度,一旦你理解了足够的代码以确定常见逻辑的部分,就把这些大型函数分解成更小的函数。它将提高您和他人的可读性。

答案 7 :(得分:2)

我小时候曾经写过这样的代码。太可怕了。最糟糕的是,这些功能的大块只是在其他地方复制/粘贴。我记得为一个乐队的粉丝网站建立了一个完整的“粉丝查找器”类型的注册表。它给了你一张世界地图,并指出每个签名的人的位置。您可以点击不同的国家/地区,按名称搜索等等,您将获得全世界所有这些粉丝的列表和列表,所有这些粉丝都有自己可以编辑的小配置文件(最喜欢的歌曲,乐队成员等) )。所有PHP都是这样的。所有使用平面文本文件......这是非常残酷的。我只是重新编写了大多数文件解析函数,在每个函数中我一次又一次地处理文本文件......我的上帝很可怕。我意识到你可能想为此扼杀我,这就是为什么我很高兴你不知道我住在哪里。

答案 8 :(得分:1)

但是,如果我还建议为原始代码编写尽可能多的单元测试用例,这几乎涵盖了此代码在进行完全重写之前所做的事情,那么我会考虑重写选项,验证它将变得非常重要你的重写正在做同样的工作。

答案 9 :(得分:1)

看起来有人需要对高凝聚力的原则进行一点复习。

答案 10 :(得分:1)

告诉给你的人,它需要重写。

看起来此函数确定用户类型,为页面生成器设置标志和内容。您可以将此功能放在流程图中并重新组织此项目。整个事情似乎很好地模仿了面向对象的编程。您可以真正降低会话全局变量的相互依赖程度,使用更小的代码并使整个事情更加健壮。

答案 11 :(得分:1)

我有一堆像这样的垃圾。我最终想出的最好的策略是弄清楚它从外面做了什么,而不是从里到外。所以这与第一响应者相反(它描述了我开始做的事情)。如果代码具有一些伪装结构,这是有道理的,但这可能不是理所当然的事情。例如,我最终找出了一堆永远不会被调用的代码。在某些情况下,相同的功能以几种不同的方式实现。浪费了很多时间。

最终会产生一个网页。可能更容易弄清楚网页的外观以及它通常如何运作,并且只需使用代码来提示哪些内容不明显。

答案 12 :(得分:1)

答案 13 :(得分:1)

不要碰它!相信我!