-
-
/**
- php xml操作類別
- link:http://bbs.it-home.org
- */
- class requirelog
- {
- protected 靜態$ requirelog;
//準備xml,若找不到xml,建立xml
- static function _initializeLog()
- {
- if(file_exists('requirelog.xml') )
- {
self::$requirelog = DOMDocument::load('requirelog.xml');
- }
- else
- {
- self: :$requirelog = new DOMDocument('1.0', 'iso-8859 -1');
- self::$requirelog->loadXML(' 內容>');
- self::$requirelog->save('requirelog.xml');
- }
- }
- //取得finish欄位全部為0的所有節點
- public static function get_entrys( )
- {
- self::_initializeLog();
- $entrys = self::$requirelog->getElementsByTagName('entry');
- $entry_arrays = array();
- foreach ($arrays = array();
- foreach ($arrays條目為$entry)
- {
- if($entry->getElementsByTagName('finish')->item(0)->nodeValue == 0)
- {
- $ Entry_array = array() ;
- $entry_array['id'] = $entry->getElementsByTagName('id')->item(0)->nodeValue;
- $entry_array['time'] = $entry->getElementsByTagName(' time')->item(0)->nodeValue;
- $entry_array['operator'] = $entry->getElementsByTagName('operator')->item (0)->nodeValue;
- $entry_array[ 'byoperator'] = $entry->getElementsByTagName('byoperator')->item(0)->nodeValue;
- $entry_array['parameters1 '] = $entry->getElementsByTagName('parameters1')->item( 0)->nodeValue;
- $entry_array['parameters2'] = $entry->getElementsByTagName('parameters2')-> ;item(0)->nodeValue;
- $entry_array['parameters3'] = $parameters3'] = $ Entry->getElementsByTagName('parameters3')->item(0)->nodeValue;
$entry_array['type'] = $entry->getElementsByTagName('type')->itemtype')->item (0)->nodeValue;
- $entry_array['module'] = $entry->getElementsByTagName(' module')->item(0)->nodeValue;
- $entry_array['finish'] = $ Entry->getElementsByTagName('finish')->item(0)->nodeValue;
- $entry_arrays[] = $entry_array;
- }
- }
- return $entry_arra;
- }
-
- //取得所有的節點
- public static function get_count_entrys()
- {
- self::_initializeLog();
- $entrys = self::$require-> Entry');
- $entry_arrays = array();
- foreach( $entrys 作為$entry)
- {
$entry_array = array();
- $ $ Entry_array['id'] = $entry->getElementsByTagName('id')->item(0)->nodeValue;
- $entry_array['time'] = $entry->getElementsByTagName('time')-> item(0)->nodeValue;
- $entry_array['operator'] = $entry->getElementsByTagName('operator')-> item(0)->nodeValue;
- $entry_array['byoperator'] = $entry->getElementsByTagName('byoperator')->item(0)->nodeValue;
- $entry_array['parameters1'] = $entry->getElementsByTagName('parameters1')->item(0)->nodeValue ;
- $entry_array['parameters2'] = $entry->getElementsByTagName('parameters2')->item(0)->nodeValue;
- $entry_array['parameters3'] = $entry->getElementsBTagyName('參數3')->item(0)->nodeValue;
$entry_array['type'] = $entry->getElementsByTagName('type')->item(0)-> nodeValue ;
- $entry_array['module'] = $entry->getElementsByTagName(' module')->item(0)->nodeValue;
- $entry_array['finish'] = $entry->getElementsByTagName( ' finish')->item(0)->nodeValue;
- $entry_arrays[] = $entry_array;
}
- 回傳 $entry_arrays; }
//依ID取得節點
- public static function get_entry($id)
- {
- self::_initializeLog();
- $count=count(self ::get_count_entrys());
- if($count > 0)
- {
- $entrys = self::$requirelog->getElementsByTagName('entry');
- foreach($entrys as $條目)
- {
- if ($id == $entry->getElementsByTagName('id')->item(0)->nodeValue)
- {
- $entry_array = array();
- $entry_array[ 'id'] = $entry->getElementsByTagName('id')->item(0)->nodeValue;
- $entry_array['time'] = $entry->getElementsByTagName('time' ) ->item(0)->nodeValue;
- $entry_array['operator'] = $entry->getElementsByTagName('operator')->item(0)->nodeValue;
- $ Entry_array['byoperator '] = $entry->getElementsByTagName('byoperator')->item(0)->nodeValue;
- $entry_array['parameters1'] = $entry->getElementsByTagName('parameters1) ')->item(0 )->nodeValue;
- $entry_array['parameters2'] = $entry->getElementsByTagName('parameters2')->item(0)->nodeValue;
- $entry_array['parameters3'] = $entry- >getElementsByTagName('parameters3')->item(0)->nodeValue;
$entry_array['type'] = $entry->getElementsByTagName('type')->item(0 )->nodeValue;
- $entry_array['module'] = $entry->getElementsByTagName(' module')->item(0)->nodeValue;
- $entry_array['finish'] = $entry- >getElementsByTagName('finish')->item(0)->nodeValue;
- 返回$entry_array;
- }
- }
- }
- else
- 返回null;
- }
// 執行完成使用者請求,更改finsh欄位
- public static function do_finsh($id)
- {
- self::_initializeLog();
- $entrys = self::$requirelog->getElementsByTagName ('entry');
- $entry_arrays = array();
- foreach($entrys as $entry)
- { if($entrys as $entry)
- { if($entry->TaggetElementsByName ('id')->; item(0)->nodeValue == $id)
- {
- $entry->getElementsByTagName('finish')->item(0)->nodeValue = 1;
- }
- }
self::$requirelog->save('requirelog.xml');
- }
//增加新節點,$operator為操作者,$byoperator是被操作對象,$parameters1,2,3為可擴展的參數,$type為類型,$module為影響的模組
- static function add_entry($operator,$byoperator,$parameters1,$parameters2,$parameters3,$type,$module)
- {
- //$contents = self::$restlog->getElementsByTagName ('contents');
self::_initializeLog();
- $count=count(self::get_count_entrys());
$ entry = self::$requirelog->createElement('entry');
$id = self::$requirelog->createElement('id');
- $idvalue = self ::$requirelog->createTextNode($count+1);
- $id->appendChild($idvalue);
$time = self::$requirelog->createElement(' time');
- $timevalue = self::$requirelog->createTextNode(date("Y-m-d H:i:s",time()));
- $time->appendChild($timevalue);
$op = self::$requirelog->createElement('operator');
- $opvalue = self::$requirelog->createTextNode($operator);
- $op ->appendChild($opvalue);
$bop = self::$requirelog->createElement('byoperator');
- $bopvalue = self::$requirelog->createTextNode( $byoperator);
- $bop->appendChild($bopvalue);
$ps1 = self::$requirelog->createElement('parameters1');
- $ps1value = self::$requirelog->createTextNode($parameters1);
- $ps1->appendChild($ps1value);
$ps2 = self::$requirelog->createElement('parameters2 ');
- $ps2value = self::$requirelog->createTextNode($parameters2);
- $ps2->appendChild($ps2value);
$ps3 = self: :$requirelog->createElement('parameters3');
- $ps3value = self::$requirelog->createTextNode($parameters3);
- $ps3->appendChild($ps3value);
- $ps3->appendChild($ps3value);
- $tp = self::$requirelog->createElement('type');
- $tpvalue = self::$requirelog->createTextNode($type);
- $tp-> appendChild($tpvalue);
$md = self::$requirelog->createElement('module');
- $mdvalue = self::$requirelog->createTextNode($module );
- $md->appendChild($mdvalue);
$fi = self::$requirelog->createElement('finish');
- $fivalue = self: :$requirelog->createTextNode(0);
- $fi->appendChild($fivalue);
$entry->appendChild($id);
- $entry-> appendChild($time);
- $entry->appendChild($op);
- $entry->appendChild($bop);
- $entry->appendChild($ps1);
- $entry ->appendChild($ps2);
- $entry->appendChild($ps3);
- $entry->appendChild($tp);
- $entry->appendChild($md);
- $entry->appendChild($fi);
self::$requirelog->documentElement->appendChild($entry);
- self::$requirelog->save('requirelog .xml');
return 1;
- }
- }
- ?>
複製程式碼
2、requirelog.xml文件,參考格式如下:
-
-
- ;
- 1
- 2009-11-21 16:56:33時間>
- peng. Zhou操作員>
- zxcxzcxzczxcxz
- cxzcxzc
-
-
- group_group
-
- group_group>
-
- group_group>
- 1完成>
-
-
- 2
- 2009-11-21 16: 56:53
- peng. Zhou操作者>
- 銷售
-
-
-
- add_member類型>
- mail_group模組> ;
1完成>
| 複製程式碼