<?php 
require('includes/application_top.php');
$action=isset($HTTP_GET_VARS['action_val'])?$HTTP_GET_VARS['action_val']:'';
$file_list=array(	'administrator.php'=>"'admin_account.php','admin_files.php','admin_members.php','email_messages.php',",
	'affiliate.php'=>"'affiliate_affiliates.php','affiliate_banners.php','affiliate_clicks.php','affiliate_contact.php','affiliate_invoice.php','affiliate_payment.php','affiliate_popup_image.php','affiliate_sales.php','affiliate_statistics.php','affiliate_summary.php',",
	'catalog.php'=>"'categories.php','easypopulate.php','featured.php','listcategories.php','manufacturers.php','products_attributes.php','products_expected.php','quick_attributes_popup.php','quick_products_popup.php','reviews.php','salemaker.php','salemaker_info.php','specials.php','xsell_products.php',",
	'configuration.php'=>"'configuration.php','referrals.php','customer_options.php','define_mainpage.php','xsell_products.php',",
	'customers.php'=>"'addevents.php','checkout_payment.php','checkout_process.php','create_account.php','create_account_process.php','create_account_success.php','create_order.php','create_order_process.php','customers.php','customers_groups.php','customer_options.php','edit_orders.php','edit_orders_confirm.php','edit_orders_process.php','edit_orders_success.php','events_id_card.php','events_ticket.php','orders.php','subscription_groups.php','wallet_confirmation.php','wallet_payment.php','wallet_process.php','wallet_success.php',",
	'event.php'=>"'events.php','events_copy_messages.php','events_discounts.php','events_locations.php','events_messages.php','events_messages_log.php','events_options.php','events_sms_messages.php','general_templates.php','preview_event_idcarts.php','pop_questions.php','preview_event_tickets.php','send_email.php','send_sms_email.php','sessions.php','waitlists.php',",
	'faqdesk.php'=>"'faqdesk.php','faqdesk_reviews.php','faqdesk_configuration.php',",
	'gv_admin.php'=>"'coupon_admin.php','coupon_restrict.php','gv_mail.php','gv_queue.php','gv_sent.php','listcategories.php','listevents.php','listproducts.php','listsubscription.php','validcategories.php','validevents.php','validproducts.php','validsubscription.php',",
	'info_boxes.php'=>"'template_configuration.php','infobox_configuration.php',",
	'instructor.php'=>"'events_admin_messages.php','events_admin_payments.php','events_admin_payments_detail.php','events_payments.php','events_payments_detail.php','instructors.php','instructors_options.php','instructor_events.php',",
	'localization.php'=>"'currencies.php','languages.php','orders_status.php',",
	'modules.php'=>"'modules.php',",
	'newsdesk.php'=>"'newsdesk.php','newsdesk_configuration.php','newsdesk_reviews.php',",
	'paypalipn.php'=>"'paypalipn_txn.php','paypalipn_tests.php',",
	'reports.php'=>"'mailing_labels.php','reports_attendance_analysis.php','reports_birthday_list.php','reports_call_centre_orders.php','reports_customer_details.php','reports_daily_reservations.php','reports_events_attendees.php','reports_events_idcards.php','reports_events_non_returns.php','reports_events_progress.php','reports_events_sales.php','reports_events_surveys.php','reports_events_surveys_detail.php','reports_events_surveys_relation.php','reports_events_surveys_summary.php','reports_events_viewed.php','reports_events_waitlist.php','reports_event_tickets.php','reports_instructor_payments.php','reports_inventory.php','reports_mailing_labels.php','reports_monthly_sales.php','reports_packing_slip.php','reports_pending_payments.php','reports_products_sales.php','reports_products_viewed.php','reports_sales_category.php','reports_sales_subscriptions.php','reports_subscriptions_sales.php','reports_subscription_details.php','reports_subscription_monthlysales.php','reports_subscription_non_renewals.php','reports_subscription_renewals.php','reports_subscription_unpaid_payments.php','reports_subscription_viewed.php','reports_unpaid_payments.php',",
	'reservation.php'=>"'events_browse.php','events_check_in.php','events_copy_surveys.php','events_surveys.php','events_surveys_answer.php','events_surveys_edit.php','events_surveys_process.php','instructor_reservations.php','move_reservations_confirm.php','move_reservations_process.php','pending_waitlist_new_order.php','pending_waitlist_payments.php','pending_waitlist_payments_confirm.php','pending_waitlist_payments_process.php','refund_confirm_reservation.php','refund_process.php','refund_reservation.php','refund_success.php','search_event.php','search_reservation.php','search_reservation_dated.php','search_reservation_print.php','search_reservation_print_dated.php','search_reservation_print_dated_pdf.php','search_reservation_print_pdf.php','withdraw_process.php','withdraw_reservation.php',",
	'subscription.php'=>"'subscription_categories.php','subscription_copy_messages.php','subscription_messages.php','subscription_messages_logs.php','subscription_send_email.php',",
	'taxes.php'=>"'countries.php','geo_zones.php','tax_classes.php','tax_rates.php','zones.php',",
	'tools.php'=>"'backup.php','banner_manager.php','banner_statistics.php','cache.php','define_language.php','file_manager.php','mail.php','newsletters.php','server_info.php','whos_online.php',");
//print_r($file_list);
$boxes_list=array();
$boxes_files=array();
while (list($key, $val) = each($file_list)) {
    $boxes_list[]=array('id'=>$key,'text'=>str_replace(".php","",$key));
    $boxes_files[]=array('id'=>$key,'text'=>$val);
    if($key=='administrator.php'){
       $files.=','.$val;
   }
   if($key=='tools.php'){
      $files.=$val.',';
   }else {
   $files.=$val;
 }
} 
$files_list=str_replace("'","",$files);
$files_list=str_replace(".php,",".php,,",$files_list);
$select_all_files=tep_db_query("select admin_files_name from admin_files");
  while($result_file=tep_db_fetch_array($select_all_files)){	
    $files_list=str_replace(",".$result_file['admin_files_name'].",","",$files_list);
 }
$files_list=split(".php",str_replace(",","",$files_list));
$Q_insert="";
while(list($f_key,$f_val)=each($files_list)){
  if($f_val!=''){
      echo "INSERT INTO admin_files (admin_files_id, admin_files_name, admin_files_is_boxes, admin_files_to_boxes, admin_groups_id) VALUES (NULL, '". $f_val.'.php'."', 1, 0, 1);<br>";
      //$Q_insert.="INSERT INTO admin_files (admin_files_id, admin_files_name, admin_files_is_boxes, admin_files_to_boxes, admin_groups_id) VALUES (NULL, '". $f_val.'.php'."', 1, 0, 1);"; 
      $Q_insert=array('admin_files_id'=>NULL,
                                     'admin_files_name'=>$f_val.'.php',
                                     'admin_files_is_boxes'=>1,
                                     'admin_files_to_boxes'=>0,
                                    'admin_groups_id'=>1);
   }
}
$query=tep_db_query("select admin_files_id as admin_boxes_id, admin_files_name as admin_boxes_name, admin_groups_id as boxes_group_id,admin_files_type as boxes_type from admin_files where admin_files_is_boxes = '1' order by admin_files_name");
 while($result=tep_db_fetch_array($query)){ 	        
         $str_len=strlen($file_list[$result['admin_boxes_name']]);
         $str=substr($file_list[$result['admin_boxes_name']],0,$str_len-2);
       if($str!=''){
         echo  '<b>#<font color="red">'.str_replace(".php","",$result['admin_boxes_name']) . '</font></b><br>';		 	  
         echo "UPDATE admin_files set admin_files_to_boxes='".$result['admin_boxes_id']."' where admin_files_id!='".$result['admin_boxes_id']."' and admin_files_name  in(".$str. "');" . '<br>';
        //$Q_upd.="UPDATE admin_files set admin_files_to_boxes='".$result['admin_boxes_id']."' where admin_files_id!='".$result['admin_boxes_id']."' and admin_files_name  in(".$str. "<br> ');";
        $Q_update[]=array('admin_files_to_boxes'=>$result['admin_boxes_id'],'files'=>$str);              
    } 
}   
if($action=='ALL') {
    if($Q_insert!='')  tep_db_perform('admin_files',$Q_insert);
   for($i=0;$i<sizeof($Q_update);$i++){
       $QUD=array('admin_files_to_boxes'=>$Q_update[$i]['admin_files_to_boxes']);  
       tep_db_perform('admin_files',$QUD,'update','admin_files_id!="'.$Q_update[$i]['admin_files_to_boxes'].'" and admin_files_name in('.$Q_update[$i]['files']."'".')');
    }	
}
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
<script language="javascript">
   function doExecute(){
           if(confirm("Are u sure want to execute this query")){
             document.f.action_val.value="ALL";
             document.f.submit();    	
           }
  }
  function Do_needed(){
    var box_n=document.f.boxes_name.value; 
   <?php 
       for($i=0;$i<sizeof($boxes_files);$i++){?> 
          if(box_n=="<?php echo $boxes_files[$i]['id'];?>"){
             var box_files="<?php echo $boxes_files[$i]['text'];?>"; 
          }     
  <?php     } ?>
  }
</script>
<form name="f" id="f" action="<?php echo $PHP_SELF;?>">
<table width="100%" border=0 cellspacing=0 cellpadding=0 align="center">
    <tr align="left">
       <td colspan="2" ailgn="left"><input type="button" value="Execute All" onclick="javascript:doExecute();"></td>
    </tr>
    <tr>
      <td align="left">
        <?php //echo tep_draw_pull_down_menu('boxes_name',$boxes_list,'','onchange="javascript:Do_needed();"') . '<br>'.tep_draw_pull_down_menu('files_list',$box_files_list);?>
    </td>
    </tr>
</table>
<input type="hidden" name="action_val"  id="action_val">
</form>