Dotclear


Ignore:
Timestamp:
10/24/13 11:14:03 (12 years ago)
Author:
Denis Jean-Chirstian <contact@…>
Branch:
2.6
Message:

Add actions batch (and checkboxes) to modules list.

Location:
inc/admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inc/admin/lib.dc.page.php

    r2328 r2487  
    665665          self::jsVar('dotclear.msg.confirm_delete_plugin', 
    666666               __('Are you sure you want to delete "%s" plugin?')). 
     667          self::jsVar('dotclear.msg.confirm_delete_plugins', 
     668               __('Are you sure you want to delete selected plugins?')). 
    667669          self::jsVar('dotclear.msg.use_this_theme', 
    668670               __('Use this theme')). 
     
    671673          self::jsVar('dotclear.msg.confirm_delete_theme', 
    672674               __('Are you sure you want to delete "%s" theme?')). 
     675          self::jsVar('dotclear.msg.confirm_delete_themes', 
     676               __('Are you sure you want to delete selected themes?')). 
    673677          self::jsVar('dotclear.msg.confirm_delete_backup', 
    674678               __('Are you sure you want to delete this backup?')). 
  • inc/admin/lib.moduleslist.php

    r2469 r2487  
    522522     { 
    523523          echo 
     524          '<form action="'.$this->getURL().'" method="post" class="modules-form-actions">'. 
    524525          '<div class="table-outer">'. 
    525526          '<table id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').'">'. 
     
    527528 
    528529          if (in_array('name', $cols)) { 
     530               $colspan = 1; 
     531               if (in_array('checkbox', $cols)) { 
     532                    $colspan++; 
     533               } 
     534               if (in_array('icon', $cols)) { 
     535                    $colspan++; 
     536               } 
    529537               echo 
    530                '<th class="first nowrap"'.(in_array('icon', $cols) ? ' colspan="2"' : '').'>'.__('Name').'</th>'; 
     538               '<th class="first nowrap"'.($colspan > 1 ? ' colspan="'.$colspan.'"' : '').'>'.__('Name').'</th>'; 
    531539          } 
    532540 
     
    590598               $tds = 0; 
    591599 
     600               if (in_array('checkbox', $cols)) { 
     601                    $tds++; 
     602                    echo 
     603                    '<td class="module-icon nowrap">'. 
     604                    form::checkbox(array('modules['.$count.']', html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id)), html::escapeHTML($id)). 
     605                    '</td>'; 
     606               } 
     607 
    592608               if (in_array('icon', $cols)) { 
    593609                    $tds++; 
     
    601617               $tds++; 
    602618               echo 
    603                '<td class="module-name nowrap" scope="row">'.html::escapeHTML($module['name']).'</td>'; 
     619               '<td class="module-name nowrap" scope="row">'; 
     620               if (in_array('checkbox', $cols)) { 
     621                    if (in_array('expander', $cols)) { 
     622                         echo 
     623                         html::escapeHTML($module['name']); 
     624                    } 
     625                    else { 
     626                         echo 
     627                         '<label for="'.html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id).'">'. 
     628                         html::escapeHTML($module['name']). 
     629                         '</label>'; 
     630                    } 
     631               } 
     632               else { 
     633                    echo 
     634                    html::escapeHTML($module['name']). 
     635                    form::hidden(array('modules['.$count.']'), html::escapeHTML($id)); 
     636               } 
     637               echo 
     638               $this->core->formNonce(). 
     639               '</td>'; 
    604640 
    605641               # Display score only for debug purpose 
     
    645681                    '<td class="module-actions nowrap">'. 
    646682 
    647                     '<form action="'.$this->getURL().'" method="post">'. 
    648                     '<div>'. 
    649                     $this->core->formNonce(). 
    650                     form::hidden(array('module'), html::escapeHTML($id)). 
    651  
    652                     implode(' ', $buttons). 
    653  
    654                     '</div>'. 
    655                     '</form>'. 
     683                    '<div>'.implode(' ', $buttons).'</div>'. 
    656684 
    657685                    '</td>'; 
     
    732760          } 
    733761 
    734           if ($count > 1 && !empty($actions) && $this->core->auth->isSuperAdmin()) { 
    735                $buttons = $this->getGlobalActions($actions); 
    736  
    737                echo 
    738                '<form action="'.$this->getURL().'" method="post" class="global-actions-buttons">'. 
    739                '<div>'. 
    740                $this->core->formNonce(). 
    741                form::hidden(array('modules'), '1'). 
    742  
    743                implode(' ', $buttons). 
    744  
    745                '</div>'. 
    746                '</form>'; 
    747           } 
     762          elseif ((in_array('checkbox', $cols) || $count > 1) && !empty($actions) && $this->core->auth->isSuperAdmin()) { 
     763               $buttons = $this->getGlobalActions($actions, in_array('checkbox', $cols)); 
     764 
     765               if (!empty($buttons)) { 
     766                    if (in_array('checkbox', $cols)) { 
     767                         echo  
     768                         '<p class="checkboxes-helpers"></p>'; 
     769                    } 
     770                    echo 
     771                    '<div>'.implode(' ', $buttons).'</div>'; 
     772               } 
     773          } 
     774          echo  
     775          '</form>'; 
    748776 
    749777          return $this; 
     
    769797                    case 'activate': if ($module['root_writable']) { 
    770798                         $submits[] = 
    771                          '<input type="submit" name="activate" value="'.__('Activate').'" />'; 
     799                         '<input type="submit" name="activate['.html::escapeHTML($id).']" value="'.__('Activate').'" />'; 
    772800                    } break; 
    773801 
     
    775803                    case 'deactivate': if ($module['root_writable']) { 
    776804                         $submits[] = 
    777                          '<input type="submit" name="deactivate" value="'.__('Deactivate').'" class="reset" />'; 
     805                         '<input type="submit" name="deactivate['.html::escapeHTML($id).']" value="'.__('Deactivate').'" class="reset" />'; 
    778806                    } break; 
    779807 
     
    782810                         $dev = !preg_match('!^'.$this->path_pattern.'!', $module['root']) && defined('DC_DEV') && DC_DEV ? ' debug' : ''; 
    783811                         $submits[] = 
    784                          '<input type="submit" class="delete '.$dev.'" name="delete" value="'.__('Delete').'" />'; 
     812                         '<input type="submit" class="delete '.$dev.'" name="delete['.html::escapeHTML($id).']" value="'.__('Delete').'" />'; 
    785813                    } break; 
    786814 
     
    788816                    case 'install': if ($this->path_writable) { 
    789817                         $submits[] = 
    790                          '<input type="submit" name="install" value="'.__('Install').'" />'; 
     818                         '<input type="submit" name="install['.html::escapeHTML($id).']" value="'.__('Install').'" />'; 
    791819                    } break; 
    792820 
     
    794822                    case 'update': if ($this->path_writable) { 
    795823                         $submits[] = 
    796                          '<input type="submit" name="update" value="'.__('Update').'" />'; 
     824                         '<input type="submit" name="update['.html::escapeHTML($id).']" value="'.__('Update').'" />'; 
    797825                    } break; 
    798826 
     
    816844      * Get global action buttons to add to modules list. 
    817845      * 
    818       * @param array     $actions  Actions keys 
     846      * @param array     $actions        Actions keys 
     847      * @param boolean   $with_selection Limit action to selected modules 
    819848      * @return     Array of actions buttons 
    820849      */ 
    821      protected function getGlobalActions($actions) 
     850     protected function getGlobalActions($actions, $with_selection=false) 
    822851     { 
    823852          $submits = array(); 
     
    830859                    case 'activate': if ($this->path_writable) { 
    831860                         $submits[] = 
    832                          '<input type="submit" name="activate" value="'.__('Activate all plugins from this list').'" />'; 
     861                         '<input type="submit" name="activate" value="'.($with_selection ? 
     862                              __('Activate selected plugins') : 
     863                              __('Activate all plugins from this list') 
     864                         ).'" />'; 
    833865                    } break; 
    834866 
     
    836868                    case 'deactivate': if ($this->path_writable) { 
    837869                         $submits[] = 
    838                          '<input type="submit" name="deactivate" value="'.__('Deactivate all plugins from this list').'" class="reset" />'; 
     870                         '<input type="submit" name="deactivate" value="'.($with_selection ? 
     871                              __('Deactivate selected plugins') : 
     872                              __('Deactivate all plugins from this list') 
     873                         ).'" />'; 
    839874                    } break; 
    840875 
     
    842877                    case 'update': if ($this->path_writable) { 
    843878                         $submits[] = 
    844                          '<input type="submit" name="update" value="'.__('Update all plugins from this list').'" />'; 
     879                         '<input type="submit" name="update" value="'.($with_selection ? 
     880                              __('Update selected plugins') : 
     881                              __('Update all plugins from this list') 
     882                         ).'" />'; 
    845883                    } break; 
    846884 
     
    849887 
    850888                         # --BEHAVIOR-- adminModulesListGetGlobalActions 
    851                          $tmp = $this->core->callBehavior('adminModulesListGetGlobalActions', $this); 
     889                         $tmp = $this->core->callBehavior('adminModulesListGetGlobalActions', $this, $with_selection); 
    852890 
    853891                         if (!empty($tmp)) { 
     
    875913          } 
    876914 
    877           # Actions per module 
    878           if (!empty($_POST['module'])) { 
    879  
    880                $id = $_POST['module']; 
    881  
    882                if (!empty($_POST['activate'])) { 
    883  
    884                     $enabled = $this->modules->getDisabledModules(); 
    885                     if (!isset($enabled[$id])) { 
    886                          throw new Exception(__('No such plugin.')); 
    887                     } 
    888  
    889                     # --BEHAVIOR-- moduleBeforeActivate 
    890                     $this->core->callBehavior('pluginBeforeActivate', $id); 
    891  
    892                     $this->modules->activateModule($id); 
    893  
    894                     # --BEHAVIOR-- moduleAfterActivate 
    895                     $this->core->callBehavior('pluginAfterActivate', $id); 
    896  
    897                     dcPage::addSuccessNotice(__('Plugin has been successfully activated.')); 
    898                     http::redirect($this->getURL()); 
    899                } 
    900  
    901                elseif (!empty($_POST['deactivate'])) { 
    902  
    903                     if (!$this->modules->moduleExists($id)) { 
    904                          throw new Exception(__('No such plugin.')); 
    905                     } 
    906  
    907                     $module = $this->modules->getModules($id); 
    908                     $module['id'] = $id; 
    909  
    910                     if (!$module['root_writable']) { 
    911                          throw new Exception(__('You don\'t have permissions to deactivate this plugin.')); 
    912                     } 
    913  
    914                     # --BEHAVIOR-- moduleBeforeDeactivate 
    915                     $this->core->callBehavior('pluginBeforeDeactivate', $module); 
    916  
    917                     $this->modules->deactivateModule($id); 
    918  
    919                     # --BEHAVIOR-- moduleAfterDeactivate 
    920                     $this->core->callBehavior('pluginAfterDeactivate', $module); 
    921  
    922                     dcPage::addSuccessNotice(__('Plugin has been successfully deactivated.')); 
    923                     http::redirect($this->getURL()); 
    924                } 
    925  
    926                elseif (!empty($_POST['delete'])) { 
    927  
    928                     $disabled = $this->modules->getDisabledModules(); 
    929                     if (!isset($disabled[$id])) { 
     915          $modules = !empty($_POST['modules']) && is_array($_POST['modules']) ? array_values($_POST['modules']) : array(); 
     916 
     917          if (!empty($_POST['delete'])) { 
     918 
     919               if (is_array($_POST['delete'])) { 
     920                    $modules = array_keys($_POST['delete']); 
     921               } 
     922 
     923               $list = $this->modules->getDisabledModules(); 
     924 
     925               $failed = false; 
     926               $count = 0; 
     927               foreach($modules as $id) 
     928               { 
     929                    if (!isset($list[$id])) { 
    930930 
    931931                         if (!$this->modules->moduleExists($id)) { 
     
    937937 
    938938                         if (!$this->isDeletablePath($module['root'])) { 
    939                               throw new Exception(__("You don't have permissions to delete this plugin.")); 
     939                              $failed = true; 
     940                              continue; 
    940941                         } 
    941942 
     
    952953                    } 
    953954 
    954                     dcPage::addSuccessNotice(__('Plugin has been successfully deleted.')); 
    955                     http::redirect($this->getURL()); 
    956                } 
    957                elseif (!empty($_POST['install'])) { 
    958  
    959                     $updated = $this->store->get(); 
    960                     if (!isset($updated[$id])) { 
    961                          throw new Exception(__('No such plugin.')); 
    962                     } 
    963  
    964                     $module = $updated[$id]; 
    965                     $module['id'] = $id; 
     955                    $count++; 
     956               } 
     957 
     958               if (!$count && $failed) { 
     959                    throw new Exception(__("You don't have permissions to delete this plugin.")); 
     960               } 
     961               elseif ($failed) { 
     962                    dcPage::addWarningNotice(__('Some plugins have not been delete.')); 
     963               } 
     964               else { 
     965                    dcPage::addSuccessNotice( 
     966                         __('Plugin has been successfully deleted.', 'Plugins have been successuflly deleted.', $count) 
     967                    ); 
     968               } 
     969               http::redirect($this->getURL()); 
     970          } 
     971 
     972          elseif (!empty($_POST['install'])) { 
     973 
     974               if (is_array($_POST['install'])) { 
     975                    $modules = array_keys($_POST['install']); 
     976               } 
     977 
     978               $list = $this->store->get(); 
     979 
     980               if (empty($list)) { 
     981                    throw new Exception(__('No such plugin.')); 
     982               } 
     983 
     984               $count = 0; 
     985               foreach($list as $id => $module) { 
     986 
     987                    if (!in_array($id, $modules)) { 
     988                         continue; 
     989                    } 
    966990 
    967991                    $dest = $this->getPath().'/'.basename($module['file']); 
     
    970994                    $this->core->callBehavior('pluginBeforeAdd', $module); 
    971995 
    972                     $ret_code = $this->store->process($module['file'], $dest); 
     996                    $this->store->process($module['file'], $dest); 
    973997 
    974998                    # --BEHAVIOR-- moduleAfterAdd 
    975999                    $this->core->callBehavior('pluginAfterAdd', $module); 
    9761000 
    977                     dcPage::addSuccessNotice($ret_code == 2 ? 
    978                          __('Plugin has been successfully updated.') : 
    979                          __('Plugin has been successfully installed.') 
     1001                    $count++; 
     1002               } 
     1003 
     1004               dcPage::addSuccessNotice( 
     1005                    __('Plugin has been successfully installed.', 'Plugins have been successuflly installed.', $count) 
     1006               ); 
     1007               http::redirect($this->getURL()); 
     1008          } 
     1009 
     1010          elseif (!empty($_POST['activate'])) { 
     1011 
     1012               if (is_array($_POST['activate'])) { 
     1013                    $modules = array_keys($_POST['activate']); 
     1014               } 
     1015 
     1016               $list = $this->modules->getDisabledModules(); 
     1017               if (empty($list)) { 
     1018                    throw new Exception(__('No such plugin.')); 
     1019               } 
     1020 
     1021               $count = 0; 
     1022               foreach($list as $id => $module) { 
     1023 
     1024                    if (!in_array($id, $modules)) { 
     1025                         continue; 
     1026                    } 
     1027 
     1028                    # --BEHAVIOR-- moduleBeforeActivate 
     1029                    $this->core->callBehavior('pluginBeforeActivate', $id); 
     1030 
     1031                    $this->modules->activateModule($id); 
     1032 
     1033                    # --BEHAVIOR-- moduleAfterActivate 
     1034                    $this->core->callBehavior('pluginAfterActivate', $id); 
     1035 
     1036                    $count++; 
     1037               } 
     1038 
     1039               dcPage::addSuccessNotice( 
     1040                    __('Plugin has been successfully activated.', 'Plugins have been successuflly activated.', $count) 
     1041               ); 
     1042               http::redirect($this->getURL()); 
     1043          } 
     1044 
     1045          elseif (!empty($_POST['deactivate'])) { 
     1046 
     1047               if (is_array($_POST['deactivate'])) { 
     1048                    $modules = array_keys($_POST['deactivate']); 
     1049               } 
     1050 
     1051               $list = $this->modules->getModules(); 
     1052               if (empty($list)) { 
     1053                    throw new Exception(__('No such plugin.')); 
     1054               } 
     1055 
     1056               $failed = false; 
     1057               $count = 0; 
     1058               foreach($list as $id => $module) { 
     1059 
     1060                    if (!in_array($id, $modules)) { 
     1061                         continue; 
     1062                    } 
     1063 
     1064                    if (!$module['root_writable']) { 
     1065                         $failed = true; 
     1066                         continue; 
     1067                    } 
     1068 
     1069                    $module[$id] = $id; 
     1070 
     1071                    # --BEHAVIOR-- moduleBeforeDeactivate 
     1072                    $this->core->callBehavior('pluginBeforeDeactivate', $module); 
     1073 
     1074                    $this->modules->deactivateModule($id); 
     1075 
     1076                    # --BEHAVIOR-- moduleAfterDeactivate 
     1077                    $this->core->callBehavior('pluginAfterDeactivate', $module); 
     1078 
     1079                    $count++; 
     1080               } 
     1081 
     1082               if ($failed) { 
     1083                    dcPage::addWarningNotice(__('Some plugins have not been deactivated.')); 
     1084               } 
     1085               else { 
     1086                    dcPage::addSuccessNotice( 
     1087                         __('Plugin has been successfully deactivated.', 'Plugins have been successuflly deactivated.', $count) 
    9801088                    ); 
    981                     http::redirect($this->getURL()); 
    982                } 
    983  
    984                elseif (!empty($_POST['update'])) { 
    985  
    986                     $updated = $this->store->get(true); 
    987                     if (!isset($updated[$id])) { 
    988                          throw new Exception(__('No such plugin.')); 
    989                     } 
    990  
    991                     if (!$this->modules->moduleExists($id)) { 
    992                          throw new Exception(__('No such plugin.')); 
    993                     } 
    994  
    995                     $tab = count($updated) > 1 ? '' : '#plugins'; 
    996  
    997                     $module = $updated[$id]; 
    998                     $module['id'] = $id; 
     1089               } 
     1090               http::redirect($this->getURL()); 
     1091          } 
     1092 
     1093          elseif (!empty($_POST['update'])) { 
     1094 
     1095               if (is_array($_POST['update'])) { 
     1096                    $modules = array_keys($_POST['update']); 
     1097               } 
     1098 
     1099               $list = $this->store->get(true); 
     1100               if (empty($list)) { 
     1101                    throw new Exception(__('No such plugin.')); 
     1102               } 
     1103 
     1104               $count = 0; 
     1105               foreach($list as $module) { 
     1106 
     1107                    if (!in_array($module['id'], $modules)) { 
     1108                         continue; 
     1109                    } 
    9991110 
    10001111                    if (!self::$allow_multi_install) { 
     
    10161127                    $this->core->callBehavior('pluginAfterUpdate', $module); 
    10171128 
    1018                     dcPage::addSuccessNotice(__('Plugin has been successfully updated.')); 
    1019                     http::redirect($this->getURL().$tab); 
    1020                } 
    1021                else { 
    1022  
    1023                     # --BEHAVIOR-- adminModulesListDoActions 
    1024                     $this->core->callBehavior('adminModulesListDoActions', $this, $id, 'plugin'); 
    1025  
    1026                } 
    1027           } 
    1028           # Global actions 
    1029           elseif (!empty($_POST['modules'])) { 
    1030  
    1031                if (!empty($_POST['activate'])) { 
    1032  
    1033                     $modules = $this->modules->getDisabledModules(); 
    1034                     if (empty($modules)) { 
    1035                          throw new Exception(__('No such plugin.')); 
    1036                     } 
    1037  
    1038                     foreach($modules as $id => $module) { 
    1039  
    1040                          # --BEHAVIOR-- moduleBeforeActivate 
    1041                          $this->core->callBehavior('pluginBeforeActivate', $id); 
    1042  
    1043                          $this->modules->activateModule($id); 
    1044  
    1045                          # --BEHAVIOR-- moduleAfterActivate 
    1046                          $this->core->callBehavior('pluginAfterActivate', $id); 
    1047  
    1048                     } 
    1049  
    1050                     dcPage::addSuccessNotice(__('Plugins have been successfully activated.')); 
    1051                     http::redirect($this->getURL()); 
    1052                } 
    1053  
    1054                elseif (!empty($_POST['deactivate'])) { 
    1055  
    1056                     $modules = $this->modules->getModules(); 
    1057                     if (empty($modules)) { 
    1058                          throw new Exception(__('No such plugin.')); 
    1059                     } 
    1060  
    1061                     $failed = false; 
    1062                     foreach($modules as $id => $module) { 
    1063                          $module[$id] = $id; 
    1064  
    1065                          if (!$module['root_writable']) { 
    1066                               $failed = true; 
    1067                               continue; 
    1068                          } 
    1069  
    1070                          # --BEHAVIOR-- moduleBeforeDeactivate 
    1071                          $this->core->callBehavior('pluginBeforeDeactivate', $module); 
    1072  
    1073                          $this->modules->deactivateModule($id); 
    1074  
    1075                          # --BEHAVIOR-- moduleAfterDeactivate 
    1076                          $this->core->callBehavior('pluginAfterDeactivate', $module); 
    1077                     } 
    1078  
    1079                     if ($failed) { 
    1080                          dcPage::addWarningNotice(__('Some plugins have not been deactivated.')); 
    1081                     } 
    1082                     else { 
    1083                          dcPage::addSuccessNotice(__('Plugins have been successfully deactivated.')); 
    1084                     } 
    1085                     http::redirect($this->getURL()); 
    1086                } 
    1087  
    1088                elseif (!empty($_POST['update'])) { 
    1089  
    1090                     $updated = $this->store->get(true); 
    1091                     if (empty($updated)) { 
    1092                          throw new Exception(__('No such plugin.')); 
    1093                     } 
    1094  
    1095                     foreach($updated as $module) { 
    1096  
    1097                          if (!self::$allow_multi_install) { 
    1098                               $dest = $module['root'].'/../'.basename($module['file']); 
    1099                          } 
    1100                          else { 
    1101                               $dest = $this->getPath().'/'.basename($module['file']); 
    1102                               if ($module['root'] != $dest) { 
    1103                                    @file_put_contents($module['root'].'/_disabled', ''); 
    1104                               } 
    1105                          } 
    1106  
    1107                          # --BEHAVIOR-- moduleBeforeUpdate 
    1108                          $this->core->callBehavior('pluginBeforeUpdate', $module); 
    1109  
    1110                          $this->store->process($module['file'], $dest); 
    1111  
    1112                          # --BEHAVIOR-- moduleAfterUpdate 
    1113                          $this->core->callBehavior('pluginAfterUpdate', $module); 
    1114                     } 
    1115  
    1116                     dcPage::addSuccessNotice(__('Plugins have been successfully updated.')); 
    1117                     http::redirect($this->getURL().'#plugins'); 
    1118                } 
    1119           } 
     1129                    $count++; 
     1130               } 
     1131 
     1132               $tab = $count && $count == count($list) ? '#plugins' : '#update'; 
     1133 
     1134               dcPage::addSuccessNotice( 
     1135                    __('Plugin has been successfully updated.', 'Plugins have been successuflly updated.', $count) 
     1136               ); 
     1137               http::redirect($this->getURL().$tab); 
     1138          } 
     1139 
    11201140          # Manual actions 
    11211141          elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file']) 
     
    11531173               ); 
    11541174               http::redirect($this->getURL().'#plugins'); 
     1175          } 
     1176 
     1177          else { 
     1178 
     1179               # --BEHAVIOR-- adminModulesListDoActions 
     1180               $this->core->callBehavior('adminModulesListDoActions', $this, $modules, 'plugin'); 
     1181 
    11551182          } 
    11561183 
     
    13441371     { 
    13451372          echo 
     1373          '<form action="'.$this->getURL().'" method="post" class="modules-form-actions">'. 
    13461374          '<div id="'.html::escapeHTML($this->list_id).'" class="modules'.(in_array('expander', $cols) ? ' expandable' : '').' one-box">'; 
    13471375 
     
    13761404               if (in_array('name', $cols) && !$current) { 
    13771405                    $line .= 
    1378                     '<h4 class="module-name">'.html::escapeHTML($module['name']).'</h4>'; 
     1406                    '<h4 class="module-name">'; 
     1407 
     1408                    if (in_array('checkbox', $cols)) { 
     1409                         $line .= 
     1410                         '<label for="'.html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id).'">'. 
     1411                         form::checkbox(array('modules['.$count.']', html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id)), html::escapeHTML($id)). 
     1412                         html::escapeHTML($module['name']). 
     1413                         '</label>'; 
     1414 
     1415                    } 
     1416                    else { 
     1417                         $line .= 
     1418                         form::hidden(array('modules['.$count.']'), html::escapeHTML($id)). 
     1419                         html::escapeHTML($module['name']); 
     1420                    } 
     1421 
     1422                    $line .= 
     1423                    $this->core->formNonce(). 
     1424                    '</h4>'; 
    13791425               } 
    13801426 
     
    14091455               if (in_array('name', $cols) && $current) { 
    14101456                    $line .= 
    1411                     '<h4 class="module-name">'.html::escapeHTML($module['name']).'</h4>'; 
     1457                    '<h4 class="module-name">'; 
     1458 
     1459                    if (in_array('checkbox', $cols)) { 
     1460                         $line .= 
     1461                         '<label for="'.html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id).'">'. 
     1462                         form::checkbox(array('modules['.$count.']', html::escapeHTML($this->list_id).'_modules_'.html::escapeHTML($id)), html::escapeHTML($id)). 
     1463                         html::escapeHTML($module['name']). 
     1464                         '</label>'; 
     1465                    } 
     1466                    else { 
     1467                         $line .= 
     1468                         form::hidden(array('modules['.$count.']'), html::escapeHTML($id)). 
     1469                         html::escapeHTML($module['name']); 
     1470                    } 
     1471 
     1472                    $line .= 
     1473                    '</h4>'; 
    14121474               } 
    14131475 
     
    15021564               if (!empty($actions)) { 
    15031565                    $line .= 
    1504                     '<form action="'.$this->getURL().'" method="post" class="actions-buttons">'. 
    1505                     '<p>'. 
    1506                     $this->core->formNonce(). 
    1507                     form::hidden(array('module'), html::escapeHTML($id)). 
    1508  
    1509                     implode(' ', $this->getActions($id, $module, $actions)). 
    1510  
    1511                     '</p>'. 
    1512                     '</form>'; 
     1566                    '<p>'.implode(' ', $this->getActions($id, $module, $actions)).'</p>'; 
    15131567               } 
    15141568 
     
    15231577               $res = $current ? $line.$res : $res.$line; 
    15241578          } 
     1579 
    15251580          echo 
    15261581          $res. 
     
    15321587          } 
    15331588 
    1534           if ($count > 1 && !empty($actions) && $this->core->auth->isSuperAdmin()) { 
    1535                $buttons = $this->getGlobalActions($actions); 
    1536  
    1537                echo 
    1538                '<form action="'.$this->getURL().'" method="post" class="global-actions-buttons">'. 
    1539                '<div>'. 
    1540                $this->core->formNonce(). 
    1541                form::hidden(array('modules'), '1'). 
    1542  
    1543                implode(' ', $buttons). 
    1544  
    1545                '</div>'. 
    1546                '</form>'; 
    1547           } 
     1589          elseif ((in_array('checkbox', $cols) || $count > 1) && !empty($actions) && $this->core->auth->isSuperAdmin()) { 
     1590               $buttons = $this->getGlobalActions($actions, in_array('checkbox', $cols)); 
     1591 
     1592               if (!empty($buttons)) { 
     1593                    echo '<div>'.implode(' ', $buttons).'</div>'; 
     1594               } 
     1595          } 
     1596 
     1597          echo 
     1598          '</form>'; 
     1599 
     1600          return $this; 
    15481601     } 
    15491602 
     
    15581611               if (in_array('select', $actions) && $this->path_writable) { 
    15591612                    $submits[] = 
    1560                     '<input type="submit" name="select" value="'.__('Use this one').'" />'; 
     1613                    '<input type="submit" name="select['.html::escapeHTML($id).']" value="'.__('Use this one').'" />'; 
    15611614               } 
    15621615          } 
     
    15681621     } 
    15691622 
    1570      protected function getGlobalActions($actions) 
     1623     protected function getGlobalActions($actions, $with_selection=false) 
    15711624     { 
    15721625          $submits = array(); 
     
    15741627          foreach($actions as $action) { 
    15751628               switch($action) { 
    1576  
    15771629 
    15781630                    # Update (from store) 
    15791631                    case 'update': if ($this->path_writable) { 
    15801632                         $submits[] = 
    1581                          '<input type="submit" name="update" value="'.__('Update all themes from this list').'" />'; 
     1633                         '<input type="submit" name="update" value="'.($with_selection ? 
     1634                              __('Update selected themes') : 
     1635                              __('Update all themes from this list') 
     1636                         ).'" />'; 
    15821637                    } break; 
    15831638 
     
    16051660          } 
    16061661 
    1607           # List actions 
    1608           if (!empty($_POST['module'])) { 
    1609  
    1610                $id = $_POST['module']; 
    1611  
    1612                if (!empty($_POST['select'])) { 
     1662          $modules = !empty($_POST['modules']) && is_array($_POST['modules']) ? array_values($_POST['modules']) : array(); 
     1663 
     1664          if (!empty($_POST['select'])) { 
     1665 
     1666               # Can select only one theme at a time! 
     1667               if (is_array($_POST['select'])) { 
     1668                    $modules = array_keys($_POST['select']); 
     1669                    $id = $modules[0]; 
    16131670 
    16141671                    if (!$this->modules->moduleExists($id)) { 
     
    16231680                    http::redirect($this->getURL().'#themes'); 
    16241681               } 
    1625                elseif (!empty($_POST['activate'])) { 
    1626  
    1627                     $enabled = $this->modules->getDisabledModules(); 
    1628                     if (!isset($enabled[$id])) { 
    1629                          throw new Exception(__('No such theme.')); 
     1682          } 
     1683 
     1684          elseif (!empty($_POST['activate'])) { 
     1685 
     1686               if (is_array($_POST['activate'])) { 
     1687                    $modules = array_keys($_POST['activate']); 
     1688               } 
     1689 
     1690               $list = $this->modules->getDisabledModules(); 
     1691               if (empty($list)) { 
     1692                    throw new Exception(__('No such theme.')); 
     1693               } 
     1694 
     1695               $count = 0; 
     1696               foreach($list as $id => $module) { 
     1697 
     1698                    if (!in_array($id, $modules)) { 
     1699                         continue; 
    16301700                    } 
    16311701 
     
    16381708                    $this->core->callBehavior('themeAfterActivate', $id); 
    16391709 
    1640                     dcPage::addSuccessNotice(__('Theme has been successfully activated.')); 
    1641                     http::redirect($this->getURL()); 
    1642                } 
    1643  
    1644                elseif (!empty($_POST['deactivate'])) { 
    1645  
    1646                     if (!$this->modules->moduleExists($id)) { 
    1647                          throw new Exception(__('No such theme.')); 
    1648                     } 
    1649  
    1650                     $module = $this->modules->getModules($id); 
    1651                     $module['id'] = $id; 
     1710                    $count++; 
     1711               } 
     1712 
     1713               dcPage::addSuccessNotice( 
     1714                    __('Theme has been successfully activated.', 'Themes have been successuflly activated.', $count) 
     1715               ); 
     1716               http::redirect($this->getURL()); 
     1717          } 
     1718 
     1719          elseif (!empty($_POST['deactivate'])) { 
     1720 
     1721               if (is_array($_POST['deactivate'])) { 
     1722                    $modules = array_keys($_POST['deactivate']); 
     1723               } 
     1724 
     1725               $list = $this->modules->getModules(); 
     1726               if (empty($list)) { 
     1727                    throw new Exception(__('No such theme.')); 
     1728               } 
     1729 
     1730               $failed = false; 
     1731               $count = 0; 
     1732               foreach($list as $id => $module) { 
     1733 
     1734                    if (!in_array($id, $modules)) { 
     1735                         continue; 
     1736                    } 
    16521737 
    16531738                    if (!$module['root_writable']) { 
    1654                          throw new Exception(__('You don\'t have permissions to deactivate this theme.')); 
    1655                     } 
     1739                         $failed = true; 
     1740                         continue; 
     1741                    } 
     1742 
     1743                    $module[$id] = $id; 
    16561744 
    16571745                    # --BEHAVIOR-- themeBeforeDeactivate 
     
    16631751                    $this->core->callBehavior('themeAfterDeactivate', $module); 
    16641752 
    1665                     dcPage::addSuccessNotice(__('Theme has been successfully deactivated.')); 
    1666                     http::redirect($this->getURL()); 
    1667                } 
    1668  
    1669                elseif (!empty($_POST['delete'])) { 
    1670  
    1671                     $disabled = $this->modules->getDisabledModules(); 
    1672                     if (!isset($disabled[$id])) { 
     1753                    $count++; 
     1754               } 
     1755 
     1756               if ($failed) { 
     1757                    dcPage::addWarningNotice(__('Some themes have not been deactivated.')); 
     1758               } 
     1759               else { 
     1760                    dcPage::addSuccessNotice( 
     1761                         __('Theme has been successfully deactivated.', 'Themes have been successuflly deactivated.', $count) 
     1762                    ); 
     1763               } 
     1764               http::redirect($this->getURL()); 
     1765          } 
     1766 
     1767          elseif (!empty($_POST['delete'])) { 
     1768 
     1769               if (is_array($_POST['delete'])) { 
     1770                    $modules = array_keys($_POST['delete']); 
     1771               } 
     1772 
     1773               $list = $this->modules->getDisabledModules(); 
     1774 
     1775               $failed = false; 
     1776               $count = 0; 
     1777               foreach($modules as $id) 
     1778               { 
     1779                    if (!isset($list[$id])) { 
    16731780 
    16741781                         if (!$this->modules->moduleExists($id)) { 
    1675                               throw new Exception(__('No such module.')); 
     1782                              throw new Exception(__('No such theme.')); 
    16761783                         } 
    16771784 
     
    16801787 
    16811788                         if (!$this->isDeletablePath($module['root'])) { 
    1682                               throw new Exception(__("You don't have permissions to delete this theme.")); 
     1789                              $failed = true; 
     1790                              continue; 
    16831791                         } 
    16841792 
     
    16951803                    } 
    16961804 
    1697                     dcPage::addSuccessNotice(__('Theme has been successfully deleted.')); 
    1698                     http::redirect($this->getURL()); 
    1699                } 
    1700  
    1701                elseif (!empty($_POST['install'])) { 
    1702  
    1703                     $updated = $this->store->get(); 
    1704                     if (!isset($updated[$id])) { 
    1705                          throw new Exception(__('No such theme.')); 
    1706                     } 
    1707  
    1708                     $module = $updated[$id]; 
    1709                     $module['id'] = $id; 
     1805                    $count++; 
     1806               } 
     1807 
     1808               if (!$count && $failed) { 
     1809                    throw new Exception(__("You don't have permissions to delete this theme.")); 
     1810               } 
     1811               elseif ($failed) { 
     1812                    dcPage::addWarningNotice(__('Some themes have not been delete.')); 
     1813               } 
     1814               else { 
     1815                    dcPage::addSuccessNotice( 
     1816                         __('Theme has been successfully deleted.', 'Themes have been successuflly deleted.', $count) 
     1817                    ); 
     1818               } 
     1819               http::redirect($this->getURL()); 
     1820          } 
     1821 
     1822          elseif (!empty($_POST['install'])) { 
     1823 
     1824               if (is_array($_POST['install'])) { 
     1825                    $modules = array_keys($_POST['install']); 
     1826               } 
     1827 
     1828               $list = $this->store->get(); 
     1829 
     1830               if (empty($list)) { 
     1831                    throw new Exception(__('No such theme.')); 
     1832               } 
     1833 
     1834               $count = 0; 
     1835               foreach($list as $id => $module) { 
     1836 
     1837                    if (!in_array($id, $modules)) { 
     1838                         continue; 
     1839                    } 
    17101840 
    17111841                    $dest = $this->getPath().'/'.basename($module['file']); 
     
    17141844                    $this->core->callBehavior('themeBeforeAdd', $module); 
    17151845 
    1716                     $ret_code = $this->store->process($module['file'], $dest); 
     1846                    $this->store->process($module['file'], $dest); 
    17171847 
    17181848                    # --BEHAVIOR-- themeAfterAdd 
    17191849                    $this->core->callBehavior('themeAfterAdd', $module); 
    17201850 
    1721                     dcPage::addSuccessNotice($ret_code == 2 ? 
    1722                          __('Theme has been successfully updated.') : 
    1723                          __('Theme has been successfully installed.') 
    1724                     ); 
    1725                     http::redirect($this->getURL()); 
    1726                } 
    1727  
    1728                elseif (!empty($_POST['update'])) { 
    1729  
    1730                     $updated = $this->store->get(true); 
    1731                     if (!isset($updated[$id])) { 
    1732                          throw new Exception(__('No such theme.')); 
    1733                     } 
    1734  
    1735                     if (!$this->modules->moduleExists($id)) { 
    1736                          throw new Exception(__('No such theme.')); 
    1737                     } 
    1738  
    1739                     $tab = count($updated) > 1 ? '' : '#themes'; 
    1740  
    1741                     $module = $updated[$id]; 
    1742                     $module['id'] = $id; 
    1743  
    1744                     if (!self::$allow_multi_install) { 
    1745                          $dest = $module['root'].'/../'.basename($module['file']); 
    1746                     } 
    1747                     else { 
    1748                          $dest = $this->getPath().'/'.basename($module['file']); 
    1749                          if ($module['root'] != $dest) { 
    1750                               @file_put_contents($module['root'].'/_disabled', ''); 
    1751                          } 
    1752                     } 
     1851                    $count++; 
     1852               } 
     1853 
     1854               dcPage::addSuccessNotice( 
     1855                    __('Theme has been successfully installed.', 'Themes have been successuflly installed.', $count) 
     1856               ); 
     1857               http::redirect($this->getURL()); 
     1858          } 
     1859 
     1860          elseif (!empty($_POST['update'])) { 
     1861 
     1862               if (is_array($_POST['update'])) { 
     1863                    $modules = array_keys($_POST['update']); 
     1864               } 
     1865 
     1866               $list = $this->store->get(true); 
     1867               if (empty($list)) { 
     1868                    throw new Exception(__('No such theme.')); 
     1869               } 
     1870 
     1871               $count = 0; 
     1872               foreach($list as $module) { 
     1873 
     1874                    if (!in_array($module['id'], $modules)) { 
     1875                         continue; 
     1876                    } 
     1877 
     1878                    $dest = $module['root'].'/../'.basename($module['file']); 
    17531879 
    17541880                    # --BEHAVIOR-- themeBeforeUpdate 
     
    17601886                    $this->core->callBehavior('themeAfterUpdate', $module); 
    17611887 
    1762                     dcPage::addSuccessNotice(__('Theme has been successfully updated.')); 
    1763                     http::redirect($this->getURL().$tab); 
    1764                } 
    1765                else { 
    1766  
    1767                     # --BEHAVIOR-- adminModulesListDoActions 
    1768                     $this->core->callBehavior('adminModulesListDoActions', $this, $id, 'theme'); 
    1769  
    1770                } 
    1771           } 
    1772           # Global actions 
    1773           elseif (!empty($_POST['modules'])) { 
    1774  
    1775                if (!empty($_POST['update'])) { 
    1776  
    1777                     $updated = $this->store->get(true); 
    1778                     if (empty($updated)) { 
    1779                          throw new Exception(__('No such theme.')); 
    1780                     } 
    1781  
    1782                     foreach($updated as $module) { 
    1783  
    1784                          if (!self::$allow_multi_install) { 
    1785                               $dest = $module['root'].'/../'.basename($module['file']); 
    1786                          } 
    1787                          else { 
    1788                               $dest = $this->getPath().'/'.basename($module['file']); 
    1789                               if ($module['root'] != $dest) { 
    1790                                    @file_put_contents($module['root'].'/_disabled', ''); 
    1791                               } 
    1792                          } 
    1793  
    1794                          # --BEHAVIOR-- moduleBeforeUpdate 
    1795                          $this->core->callBehavior('themesBeforeUpdate', $module); 
    1796  
    1797                          $this->store->process($module['file'], $dest); 
    1798  
    1799                          # --BEHAVIOR-- moduleAfterUpdate 
    1800                          $this->core->callBehavior('themesAfterUpdate', $module); 
    1801                     } 
    1802  
    1803                     dcPage::addSuccessNotice(__('Themes have been successfully updated.')); 
    1804                     http::redirect($this->getURL().'#themes'); 
    1805                } 
    1806           } 
     1888                    $count++; 
     1889               } 
     1890 
     1891               $tab = $count && $count == count($list) ? '#themes' : '#update'; 
     1892 
     1893               dcPage::addSuccessNotice( 
     1894                    __('Theme has been successfully updated.', 'Themes have been successuflly updated.', $count) 
     1895               ); 
     1896               http::redirect($this->getURL().$tab); 
     1897          } 
     1898 
    18071899          # Manual actions 
    18081900          elseif (!empty($_POST['upload_pkg']) && !empty($_FILES['pkg_file']) 
     
    18421934          } 
    18431935 
     1936          else { 
     1937 
     1938               # --BEHAVIOR-- adminModulesListDoActions 
     1939               $this->core->callBehavior('adminModulesListDoActions', $this, $modules, 'theme'); 
     1940 
     1941          } 
     1942 
    18441943          return null; 
    18451944     } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map