includes/pageutils.php
changeset 679 80bf9b8fe6aa
parent 621 68f8a9cc0a18
child 685 17ebe24cdf85
equal deleted inserted replaced
678:c5d4ce19e640 679:80bf9b8fe6aa
  1963               'color'        => $color
  1963               'color'        => $color
  1964               );
  1964               );
  1965           }
  1965           }
  1966           
  1966           
  1967           break;
  1967           break;
       
  1968         case 'list_presets':
       
  1969           $presets = array();
       
  1970           $q = $db->sql_query('SELECT page_id AS preset_name, rule_id, rules FROM ' . table_prefix . "acl WHERE target_type = " . ACL_TYPE_PRESET . ";");
       
  1971           if ( !$q )
       
  1972             $db->die_json();
       
  1973           
       
  1974           while ( $row = $db->fetchrow() )
       
  1975           {
       
  1976             $row['rules'] = $session->string_to_perm($row['rules']);
       
  1977             $presets[] = $row;
       
  1978           }
       
  1979           
       
  1980           return array(
       
  1981             'mode' => 'list_existing',
       
  1982             'presets' => $presets
       
  1983           );
       
  1984           break;
       
  1985         case 'save_preset':
       
  1986           if ( empty($parms['preset_name']) )
       
  1987           {
       
  1988             return array(
       
  1989               'mode' => 'error',
       
  1990               'error' => $lang->get('acl_err_preset_name_empty')
       
  1991             );
       
  1992           }
       
  1993           $preset_name = $db->escape($parms['preset_name']);
       
  1994           $q = $db->sql_query('DELETE FROM ' . table_prefix . "acl WHERE target_type = " . ACL_TYPE_PRESET . " AND page_id = '$preset_name';");
       
  1995           if ( !$q )
       
  1996             $db->die_json();
       
  1997           
       
  1998           $perms = $session->perm_to_string($parms['perms']);
       
  1999           if ( !$perms )
       
  2000           {
       
  2001             return array(
       
  2002               'mode' => 'error',
       
  2003               'error' => $lang->get('acl_err_preset_is_blank')
       
  2004             );
       
  2005           }
       
  2006           
       
  2007           $perms = $db->escape($perms);
       
  2008           $q = $db->sql_query('INSERT INTO ' . table_prefix . "acl(page_id, target_type, rules) VALUES\n"
       
  2009                             . "  ( '$preset_name', " . ACL_TYPE_PRESET . ", '$perms' );");
       
  2010           if ( !$q )
       
  2011             $db->die_json();
       
  2012           
       
  2013           return array(
       
  2014               'mode' => 'success'
       
  2015             );
       
  2016           break;
  1968         default:
  2017         default:
  1969           return Array('mode'=>'error','error'=>'Hacking attempt');
  2018           return Array('mode'=>'error','error'=>'Hacking attempt');
  1970           break;
  2019           break;
  1971       }
  2020       }
  1972     }
  2021     }