<commit_before><?php
/**
 * TipManager is a namespace that should be added to your administration interface
 * if you are using DB aware tips.
 * 
 * Once added it will appear in the application menu and will not require any
 * additional code
 * 
 * Use descendants if you want to change its looks
 * 
 * Created on 08.09.2006 by *Camper* (<EMAIL>)
 */
class TipManager extends Namespace{
	public $tip_types=array('regular'=>'regular','trigger'=>'trigger','announce'=>'announce');
	
	function initNamespace(){
		//use tips to show help on how to use them
		$this->api->getElement('menu')->addMenuItem('Tip manager',$this->short_name.';Index');
	}
    function initLayout(){
        parent::initLayout();
		//$this->elements['menu']=$this->api->getElement('menu');
        $this->template->del('LeftSidebar');
        $this->template->del('RightSidebar');
        $this->template->del('InfoWindow');
        $this->template->del('Locator');
        $this->template->del('Content');
        $this->template->del('Menu');
        //$this->template->del('SelfTips');
        
        //$this->api->init();

		$this->tips=$this->getTipsFromTemplate();
		$tip=$this->add('Tip','regular','Locator')
			->setStaticSource($this->tips)
			->setSection($this->api->page?$this->api->page:'Index')
		;
    }
	function getTipsFromTemplate(){
		$template=$this->add('SMlite');
		$template->loadTemplate('tipmanager');
		$tips=explode("[/row]",$template->get('SelfTips'));
		$result=array();
		foreach($tips as $tip){
			$tip=split(';',$tip);
			$result[]=array(
				'id'=>trim($tip[0]),
				'type'=>trim($tip[1]),
				'title'=>trim($tip[2]),
				'tip'=>trim($tip[3]),
				'sections'=>trim($tip[4]),
				'ord'=>trim($tip[5])
			);
		}
		return $result;
	}
	function defaultTemplate(){
        return array('shared','_top');
	}
	function page_Index($p){
		$filter=$this->frame('Content','Quick search')->add('TipFilter',null,'content');
		$grid=$this->add('Grid',null,'Content');
		$grid
			->addColumn('text','type','Type')
			->addColumn('shorttext','sections','Used in sections')
			->addColumn('shorttext,wrap','tip','Text')
			
			->setSource('tip')
		;
		$grid->addButton('Add new')->redirect('EditTip');
		$grid->add('Paginator',null,'paginator');
		$filter->useDQ($grid->dq);
	}
	function page_EditTip($p){
		$form=$this->frame('Content','Tip params')->add('Form',null,'content');
		$form
			->addField('dropdown','type','Tip type')->setValueList($this->tip_types)
			->addField('text','tip','Text')->setNotNull()
			->addField('line','sections','Used in sections')
			
			->setSource('tip')
			->addConditionFromGET('id')
			
			->addSubmit('Save')
			->addButton('Cancel')->redirect('Index')
		;
		if($form->isSubmitted()){
			$form->update();
			$this->api->redirect('Index');
		}<commit_msg>must use $p not $this<commit_after><?php
/**
 * TipManager is a namespace that should be added to your administration interface
 * if you are using DB aware tips.
 * 
 * Once added it will appear in the application menu and will not require any
 * additional code
 * 
 * Use descendants if you want to change its looks
 * 
 * Created on 08.09.2006 by *Camper* (<EMAIL>)
 */
class TipManager extends Namespace{
	public $tip_types=array('regular'=>'regular','trigger'=>'trigger','announce'=>'announce');
	
	function initNamespace(){
		//use tips to show help on how to use them
		$this->api->getElement('menu')->addMenuItem('Tip manager',$this->short_name.';Index');
	}
    function initLayout(){
        parent::initLayout();
		//$this->elements['menu']=$this->api->getElement('menu');
        $this->template->del('LeftSidebar');
        $this->template->del('RightSidebar');
        $this->template->del('InfoWindow');
        $this->template->del('Locator');
        $this->template->del('Content');
        $this->template->del('Menu');
        //$this->template->del('SelfTips');
        
        //$this->api->init();

		$this->tips=$this->getTipsFromTemplate();
		$tip=$this->add('Tip','regular','Locator')
			->setStaticSource($this->tips)
			->setSection($this->api->page?$this->api->page:'Index')
		;
    }
	function getTipsFromTemplate(){
		$template=$this->add('SMlite');
		$template->loadTemplate('tipmanager');
		$tips=explode("[/row]",$template->get('SelfTips'));
		$result=array();
		foreach($tips as $tip){
			$tip=split(';',$tip);
			$result[]=array(
				'id'=>trim($tip[0]),
				'type'=>trim($tip[1]),
				'title'=>trim($tip[2]),
				'tip'=>trim($tip[3]),
				'sections'=>trim($tip[4]),
				'ord'=>trim($tip[5])
			);
		}
		return $result;
	}
	function defaultTemplate(){
        return array('shared','_top');
	}
	function page_Index($p){
		$filter=$p->frame('Content','Quick search')->add('TipFilter',null,'content');
		$grid=$this->add('Grid',null,'Content');
		$grid
			->addColumn('text','type','Type')
			->addColumn('shorttext','sections','Used in sections')
			->addColumn('shorttext,wrap','tip','Text')
			
			->setSource('tip')
		;
		$grid->addButton('Add new')->redirect('EditTip');
		$grid->add('Paginator',null,'paginator');
		$filter->useDQ($grid->dq);
	}
	function page_EditTip($p){
		$form=$p->frame('Content','Tip params')->add('Form',null,'content');
		$form
			->addField('dropdown','type','Tip type')->setValueList($this->tip_types)
			->addField('text','tip','Text')->setNotNull()
			->addField('line','sections','Used in sections')
			
			->setSource('tip')
			->addConditionFromGET('id')
			
			->addSubmit('Save')
			->addButton('Cancel')->redirect('Index')
		;
		if($form->isSubmitted()){
			$form->update();
			$this->api->redirect('Index');
		}
{'fraction_non_alphanumeric': 0.2299139167862267, 'fraction_numerical': 0.005021520803443328, 'mean_word_length': 4.462291870714985, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 153, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6692832', 'n_tokens_mistral': 1973, 'n_tokens_neox': 1771, 'n_words': 292}