123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627 |
- <?php
- if (! function_exists('__')) {
- function __($str, $default=null, $module="GENERAL") {
- return $str;
- }
- }
- $opts['display']['time'] = false;
- $skipOpts = array();
- foreach ($opts['fdd'] as $k => $v) {
- if (isset($skipOpts[$k])) continue;
- $k2 = $k;
- if (ereg('^`.*`$', $k)) $k2 = substr($k, 1, -1);
- $tb = $opts['tb'];
- if ($opts['tb2']) $tb = $opts['tb2'];
- $opts['fdd'][$k]['name'] = __($k2, $v['name'],$tb);
- if (isset($opts['fdd'][$k.'x'])) {
- $skipOpts[$k.'x'] = 1;
- $opts['fdd'][$k.'x']['name'] = $opts['fdd'][$k]['name'];
- }
- }
- /*
- * phpMyEdit - instant MySQL table editor and code generator
- *
- * phpMyEdit.class.php - main table editor class definition file
- * ____________________________________________________________
- *
- * Copyright (c) 1999-2002 John McCreesh <jpmcc@users.sourceforge.net>
- * Copyright (c) 2001-2002 Jim Kraai <jkraai@users.sourceforge.net>
- * Versions 5.0 and higher developed by Ondrej Jombik <nepto@php.net>
- * Copyright (c) 2002-2004 Platon SDG, http://platon.sk/
- * All rights reserved.
- *
- * See README file for more information about this software.
- * See COPYING file for license information.
- *
- * Download the latest version from
- * http://platon.sk/projects/phpMyEdit/
- */
- /* $Platon: phpMyEdit/phpMyEdit.class.php,v 1.121 2004/01/26 17:17:49 nepto Exp $ */
- /* This is a generic table editing program. The table and fields to be
- edited are defined in the calling program.
- This program works in three passes.
- * Pass 1 (the last part of the program) displays the selected MySQL
- table in a scrolling table on the screen. Radio buttons are used to
- select a record for editing or deletion. If the user chooses Add,
- Change, Copy, View or Delete buttons.
- * Pass 2 starts, displaying the selected record. If the user chooses
- the Save button from this screen.
- * Pass 3 processes the update and the display returns to the
- original table view (Pass 1).
- */
- class phpMyEdit_timer /* {{{ */
- {
- var $startTime;
- var $started;
- function phpMyEdit_timer($start = true)
- {
- $this->started = false;
- if ($start) {
- $this->start();
- }
- }
- function start()
- {
- $startMtime = explode(' ', microtime());
- $this->startTime = (double) $startMtime[0] + (double) $startMtime[1];
- $this->started = true;
- }
- function end($iterations = 1)
- {
- // get the time, check whether the timer was started later
- $endMtime = explode(' ', microtime());
- if ($this->started) {
- $endTime = (double)($endMtime[0])+(double)($endMtime[1]);
- $dur = $endTime - $this->startTime;
- $avg = 1000 * $dur / $iterations;
- $avg = round(1000 * $avg) / 1000;
- return $avg;
- } else {
- return 'phpMyEdit_timer ERROR: timer not started';
- }
- }
- } /* }}} */
- if (! function_exists('array_search')) { /* {{{ */
- function array_search($needle, $haystack)
- {
- foreach ($haystack as $key => $value) {
- if ($needle == $value)
- return $key;
- }
- return false;
- }
- } /* }}} */
- if (! function_exists('realpath')) { /* {{{ */
- function realpath($path)
- {
- return $path;
- }
- } /* }}} */
- class phpMyEdit
- {
- // Class variables {{{
- // Database handling
- var $hn; // hostname
- var $un; // user name
- var $pw; // password
- var $db; // database
- var $tb; // table
- var $dbh; // database handle
- // Record manipulation
- var $key; // name of field which is the unique key
- var $key_num; // number of field which is the unique key
- var $key_type; // type of key field (int/real/string/date etc.)
- var $key_delim; // character used for key value quoting
- var $rec; // number of record selected for editing
- var $inc; // number of records to display
- var $fm; // first record to display
- var $fl; // is the filter row displayed (boolean)
- var $fds; // sql field names
- var $num_fds; // number of fields
- var $options; // options for users: ACDFVPI
- var $fdd; // field definitions
- var $qfn; // value of all filters used during the last pass
- var $sfn; // sort field number (- = descending sort order)
- // Operation
- var $navop; // navigation buttons/operations
- var $sw; // filter display/hide/clear button
- var $operation; // operation to do: Add, Change, Delete
- var $saveadd;
- var $moreadd;
- var $mailchange;
- var $docchange;
- var $rtfgen_detail;
- var $rtfgen;
- var $savechange;
- var $adminchange;
- var $savedelete;
- var $canceladd;
- var $cancelview;
- var $cancelchange;
- var $canceldelete;
- // Additional features
- var $labels; // multilingual labels
- var $cgi; // CGI variable features array
- var $url; // URL array
- var $message; // informational message to print
- var $notify; // change notification e-mail adresses
- var $logtable; // name of optional logtable
- var $navigation; // navigation style
- var $tabs; // TAB names
- var $timer = null; // phpMyEdit_timer object
- // Predefined variables
- var $comp_ops = array('<'=>'<','<='=>'<=','='=>'=','>='=>'>=','>'=>'>');
- var $sql_aggrs = array(
- 'sum' => 'Total',
- 'avg' => 'Average',
- 'min' => 'Minimum',
- 'max' => 'Maximum',
- 'count' => 'Count');
- var $page_types = array(
- 'L' => 'list',
- 'F' => 'filter',
- 'A' => 'add',
- 'V' => 'view',
- 'C' => 'change',
- 'P' => 'copy',
- 'D' => 'delete'
- );
- // }}}
- /*
- * column specific functions
- */
- function col_has_sql($k) { return isset($this->fdd[$k]['sql']); }
- function col_has_sqlw($k) { return isset($this->fdd[$k]['sqlw']) && !$this->virtual($k); }
- function col_has_values($k) { return isset($this->fdd[$k]['values']) || isset($this->fdd[$k]['values2']); }
- function col_has_URL($k) { return isset($this->fdd[$k]['URL'])
- || isset($this->fdd[$k]['URLprefix']) || isset($this->fdd[$k]['URLpostfix']); }
- function col_has_multiple_select($k)
- { return $this->fdd[$k]['select'] == 'M' && ! $this->fdd[$k]['values']['table']; }
- function col_has_datemask($k)
- { return isset($this->fdd[$k]['datemask']) || isset($this->fdd[$k]['strftimemask']); }
- /*
- * functions for indicating whether navigation style is enabled
- */
- function nav_buttons() { return stristr($this->navigation, 'B'); }
- function nav_text_links() { return stristr($this->navigation, 'T'); }
- function nav_graphic_links() { return stristr($this->navigation, 'G'); }
- function nav_up() { return stristr($this->navigation, 'U'); }
- function nav_down() { return stristr($this->navigation, 'D'); }
- /*
- * functions for indicating whether operations are enabled
- */
- function initial_sort_suppressed() { return (stristr ($this->options, 'I')); }
- function add_enabled() { return stristr($this->options, 'A'); }
- function change_enabled() { return stristr($this->options, 'C'); }
- function delete_enabled($key_rec=null) {
- if (is_null($key_rec) && $_GET['rec']) $key_rec = $_GET['rec'];
- if (is_null($key_rec) && $_POST['rec']) $key_rec = $_POST['rec'];
- if (function_exists('flag_enabled')) if (flag_enabled($key_rec) !== 1) return false;
- return stristr($this->options, 'D');
- }
- function filter_enabled() { return stristr($this->options, 'F'); }
- function view_enabled() { return stristr($this->options, 'V'); }
- function copy_enabled() { return stristr($this->options, 'P') && $this->add_enabled(); }
- function tabs_enabled() { return $this->display['tabs'] && count($this->tabs) > 0; }
- function hidden($k) { return stristr($this->fdd[$k]['input'],'H') || stristr($this->fdd[$k]['options'],'H'); }
- function password($k) { return stristr($this->fdd[$k]['input'],'W') || stristr($this->fdd[$k]['options'],'W'); }
- function readonly($k) { return stristr($this->fdd[$k]['input'],'R') || stristr($this->fdd[$k]['options'],'R') || $this->virtual($k); }
- function virtual($k) { return stristr($this->fdd[$k]['input'],'V') && $this->col_has_sql($k); }
- function add_operation() { return $this->operation == $this->labels['Add'] && $this->add_enabled(); }
- function change_operation() { return $this->operation == $this->labels['Change'] && $this->change_enabled(); }
- function copy_operation() { return $this->operation == $this->labels['Copy'] && $this->copy_enabled(); }
- function delete_operation() { return $this->operation == $this->labels['Delete'] && $this->delete_enabled(); }
- function view_operation() { return $this->operation == $this->labels['View'] && $this->view_enabled(); }
- function filter_operation() { return $this->fl && $this->filter_enabled() && $this->list_operation(); }
- function list_operation() { /* covers also filtering page */ return ! $this->change_operation()
- && ! $this->add_operation() && ! $this->copy_operation()
- && ! $this->delete_operation() && ! $this->view_operation(); }
- function next_operation() { return $this->navop == $this->labels['Next']; }
- function prev_operation() { return $this->navop == $this->labels['Prev']; }
- function first_operation() { return $this->navop == $this->labels['First']; }
- function last_operation() { return $this->navop == $this->labels['Last']; }
- function goto_operation() { return $this->navop == $this->labels['Go to']; }
- function clear_operation() { return $this->sw == $this->labels['Clear']; }
- function add_canceled() { return $this->canceladd == $this->labels['Cancel']; }
- function view_canceled() { return $this->cancelview == $this->labels['Cancel']; }
- function change_canceled() { return $this->cancelchange == $this->labels['Cancel']; }
- function delete_canceled() { return $this->canceldelete == $this->labels['Cancel']; }
- function is_values2($k, $val = 'X') /* {{{ */
- {
- return $val === null ||
- (isset($this->fdd[$k]['values2']) && !isset($this->fdd[$k]['values']['table']));
- } /* }}} */
- function processed($k) /* {{{ */
- {
- if ($this->virtual($k)) {
- return false;
- }
- $options = @$this->fdd[$k]['options'];
- if (! isset($options)) {
- return true;
- }
- return
- ($this->saveadd == $this->labels['Save'] && stristr($options, 'A')) ||
- ($this->moreadd == $this->labels['More'] && stristr($options, 'A')) ||
- ($this->savechange == $this->labels['Save'] && stristr($options, 'C')) ||
- ($this->morechange == $this->labels['Apply'] && stristr($options, 'C')) ||
- // ($this->mailchange == $this->labels['Mail'] && stristr($options, 'C')) ||
- // ($this->docchange == $this->labels['Document'] && stristr($options, 'C')) ||
- ($this->savechange == $this->labels['Save'] && stristr($options, 'P')) ||
- ($this->adminchange == $this->labels['Save'] && stristr($options, 'P')) ||
- ($this->adminchange == $this->labels['Save'] && stristr($options, 'C')) ||
- ($this->savedelete == $this->labels['Save'] && stristr($options, 'D'));
- } /* }}} */
- function displayed($k) /* {{{ */
- {
- if (is_numeric($k)) {
- $k = $this->fds[$k];
- }
- $options = @$this->fdd[$k]['options'];
- if (! isset($options)) {
- return true;
- }
- return
- ($this->add_operation() && stristr($options, 'A')) ||
- ($this->view_operation() && stristr($options, 'V')) ||
- ($this->change_operation() && stristr($options, 'C')) ||
- ($this->copy_operation() && stristr($options, 'P')) ||
- ($this->delete_operation() && stristr($options, 'D')) ||
- ($this->filter_operation() && stristr($options, 'F')) ||
- ($this->list_operation() && stristr($options, 'L'));
- } /* }}} */
- function debug_var($name, $val) /* {{{ */
- {
- if (is_array($val) || is_object($val)) {
- echo "<pre>$name\n";
- ob_start();
- //print_r($val);
- var_dump($val);
- $content = ob_get_contents();
- ob_end_clean();
- echo htmlspecialchars($content);
- echo "</pre>\n";
- } else {
- echo 'debug_var()::<i>',htmlspecialchars($name),'</i>';
- echo '::<b>',htmlspecialchars($val),'</b>::',"<br>\n";
- }
- } /* }}} */
- function myquery($qry, $line = 0, $debug = 0) /* {{{ */
- {
- global $debug_query;
- if ($debug_query || $debug) {
- $line = intval($line);
- echo '<h4>MySQL query at line ',$line,'</h4>',htmlspecialchars($qry),'<hr>',"\n";
- }
- $ret = @mysql_db_query($this->db, $qry, $this->dbh);
- if (! $ret) {
- echo '<font color=red>';
- echo '<h4>MySQL error ',mysql_errno($this->dbh),'</h4>';
- echo htmlspecialchars(mysql_error($this->dbh)),'<hr>',"\n";
- echo '</font>';
- }
- return $ret;
- } /* }}} */
- function make_language_labels($language) /* {{{ */
- {
- // just try the first language and variant
- // this isn't content-negotiation rfc compliant
- $language = strtoupper(substr($language,0,5));
- // try the full language w/ variant
- $file = $this->dir['lang'].'PME.lang.'.$language.'.inc';
- if (false && ! file_exists($file)) {
- // try the language w/o variant
- $file = $this->dir['lang'].'PME.lang.'.substr($language,0,2).'.inc';
- }
- if (true || ! file_exists($file)) {
- // default to classical English
- $file = $this->dir['lang'].'PME.lang.EN.inc';
- }
- $ret = @include($file);
- if (! is_array($ret)) {
- return $ret;
- }
- $small = array(
- 'Search' => 'v',
- 'Hide' => '^',
- 'Clear' => 'X',
- 'Query' => htmlspecialchars('>'));
- if ((!$this->nav_text_links() && !$this->nav_graphic_links())
- || !isset($ret['Search']) || !isset($ret['Query'])
- || !isset($ret['Hide']) || !isset($ret['Clear'])) {
- foreach ($small as $key => $val) {
- $ret[$key] = $val;
- }
- }
- return $ret;
- } /* }}} */
- function set_values($field_num, $prepend = null, $append = null, $strict = false) /* {{{ */
- {
- return (array) $prepend + (array) $this->fdd[$field_num]['values2']
- + (isset($this->fdd[$field_num]['values']['table']) || $strict
- ? $this->set_values_from_table($field_num, $strict)
- : array())
- + (array) $append;
- } /* }}} */
- function set_values_from_table($field_num, $strict = false) /* {{{ */
- {
- $db = &$this->fdd[$field_num]['values']['db'];
- $table = &$this->fdd[$field_num]['values']['table'];
- $key = &$this->fdd[$field_num]['values']['column'];
- $desc = &$this->fdd[$field_num]['values']['description'];
- isset($db) || $db = $this->db;
- $qparts['type'] = 'select';
- if ($table) {
- $qparts['select'] = 'DISTINCT '.$table.'.'.$key;
- if ($desc && is_array($desc) && is_array($desc['columns'])) {
- $qparts['select'] .= ',CONCAT('; // )
- $num_cols = sizeof($desc['columns']);
- if (isset($desc['divs'][-1])) {
- $qparts['select'] .= '"'.addslashes($desc['divs'][-1]).'",';
- }
- foreach ($desc['columns'] as $key => $val) {
- if ($val) {
- $qparts['select'] .= $val;
- if ($desc['divs'][$key]) {
- $qparts['select'] .= ',"'.addslashes($desc['divs'][$key]).'"';
- }
- $qparts['select'] .= ',';
- }
- }
- $qparts['select']{strlen($qparts['select']) - 1} = ')';
- $qparts['select'] .= ' AS PMEalias'.$field_num;
- $qparts['orderby'] = empty($desc['orderby'])
- ? 'PMEalias'.$field_num : $desc['orderby'];
- } else if ($desc && is_array($desc)) {
- // TODO
- } else if ($desc) {
- $qparts['select'] .= ','.$table.'.'.$desc;
- $qparts['orderby'] = $desc;
- } else if ($key) {
- $qparts['orderby'] = $key;
- }
- //$qparts['from'] = "$db.$table.$sel;
- $qparts['from'] = "$db.$table";
- $qparts['where'] = $this->fdd[$field_num]['values']['filters'];
- if ($this->fdd[$field_num]['values']['orderby']) {
- $qparts['orderby'] = $this->fdd[$field_num]['values']['orderby'];
- }
- } else { /* simple value extraction */
- $key = &$this->fds[$field_num];
- $this->virtual($field_num) && $key = $this->fqn($field_num);
- $qparts['select'] = 'DISTINCT '.$key.' AS PMEkey';
- $qparts['orderby'] = 'PMEkey';
- $qparts['from'] = $this->db.'.'.$this->tb;
- }
- $values = array();
- $res = $this->myquery($this->query_make($qparts), __LINE__);
- while ($row = @mysql_fetch_array($res, MYSQL_NUM)) {
- $values[$row[0]] = $desc ? $row[1] : $row[0];
- }
- return $values;
- } /* }}} */
- function fqn($field, $dont_desc = false, $dont_cols = false) /* {{{ */
- {
- is_numeric($field) || $field = array_search($field, $this->fds);
- // if read SQL expression exists use it
- if ($this->col_has_sql($field))
- return $this->fdd[$field]['sql'];
- // on copy/change always use simple key retrieving
- if ($this->add_operation()
- || $this->copy_operation()
- || $this->change_operation()) {
- $ret = 'PMEtable0.'.$this->fds[$field];
- } else {
- if ($this->fdd[$this->fds[$field]]['values']['description'] && ! $dont_desc) {
- $desc = &$this->fdd[$this->fds[$field]]['values']['description'];
- if (is_array($desc) && is_array($desc['columns'])) {
- $ret = 'CONCAT('; // )
- $num_cols = sizeof($desc['columns']);
- if (isset($desc['divs'][-1])) {
- $ret .= '"'.addslashes($desc['divs'][-1]).'",';
- }
- foreach ($desc['columns'] as $key => $val) {
- if ($val) {
- $ret .= 'PMEjoin'.$field.'.'.$val;
- if ($desc['divs'][$key]) {
- $ret .= ',"'.addslashes($desc['divs'][$key]).'"';
- }
- $ret .= ',';
- }
- }
- $ret{strlen($ret) - 1} = ')';
- } else if (is_array($desc)) {
- // TODO
- } else {
- $ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['description'];
- }
- // TODO: remove me
- } elseif (0 && $this->fdd[$this->fds[$field]]['values']['column'] && ! $dont_cols) {
- $ret = 'PMEjoin'.$field.'.'.$this->fdd[$this->fds[$field]]['values']['column'];
- } else {
- $ret = 'PMEtable0.'.$this->fds[$field];
- }
- // TODO: not neccessary, remove me!
- if (is_array($this->fdd[$this->fds[$field]]['values2'])) {
- }
- }
- return $ret;
- } /* }}} */
- function create_column_list() /* {{{ */
- {
- $fields = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
- if (! $this->displayed[$k] && $k != $this->key_num) {
- continue;
- }
- $fields[] = $this->fqn($k).' AS qf'.$k;
- if ($this->col_has_values($k)) {
- $fields[] = $this->fqn($k, true, true).' AS qf'.$k.'_idx';
- }
- if ($this->col_has_datemask($k)) {
- $fields[] = 'UNIX_TIMESTAMP('.$this->fqn($k).') AS qf'.$k.'_timestamp';
- }
- }
- return join(',', $fields);
- } /* }}} */
- function query_make($parts) /* {{{ */
- {
- foreach ($parts as $k => $v) {
- $parts[$k] = trim($parts[$k]);
- }
- switch ($parts['type']) {
- case 'select':
- $ret = 'SELECT ';
- if ($parts['DISTINCT'])
- $ret .= 'DISTINCT ';
- $ret .= $parts['select'];
- $ret .= ' FROM '.$parts['from'];
- if ($parts['where'] != '')
- $ret .= ' WHERE '.$parts['where'];
- if ($parts['groupby'] != '')
- $ret .= ' GROUP BY '.$parts['groupby'];
- if ($parts['having'] != '')
- $ret .= ' HAVING '.$parts['having'];
- if ($parts['orderby'] != '')
- $ret .= ' ORDER BY '.$parts['orderby'];
- if ($parts['limit'] != '')
- $ret .= ' LIMIT '.$parts['limit'];
- if ($parts['procedure'] != '')
- $ret .= ' PROCEDURE '.$parts['procedure'];
- break;
- case 'update':
- $ret = 'UPDATE '.$parts['table'];
- $ret .= ' SET '.$parts['fields'];
- if ($parts['where'] != '')
- $ret .= ' WHERE '.$parts['where'];
- break;
- case 'insert':
- $ret = 'INSERT INTO '.$parts['table'];
- $ret .= ' VALUES '.$parts['values'];
- break;
- case 'delete':
- $ret = 'DELETE FROM '.$parts['table'];
- if ($parts['where'] != '')
- $ret .= ' WHERE '.$parts['where'];
- break;
- default:
- die('unknown query type');
- break;
- }
- return $ret;
- } /* }}} */
- function create_join_clause() /* {{{ */
- {
- $tbs[] = $this->tb;
- $join = $this->tb.' AS PMEtable0';
- for ($k = 0,$numfds = sizeof($this->fds); $k<$numfds; $k++) {
- $field = $this->fds[$k];
- if($this->fdd[$field]['values']['db']) {
- $db = $this->fdd[$field]['values']['db'];
- } else {
- $db = $this->db;
- }
- $table = $this->fdd[$field]['values']['table'];
- $id = $this->fdd[$field]['values']['column'];
- $desc = $this->fdd[$field]['values']['description'];
- if ($desc != '' && $id != '') {
- $alias = 'PMEjoin'.$k;
- if (!in_array($alias,$tbs)) {
- $join .= " LEFT OUTER JOIN $db.$table AS $alias";
- $join .= " ON $alias.$id = PMEtable0.$field";
- $tbs[]=$alias;
- }
- }
- }
- return $join;
- } /* }}} */
- function make_where_from_query_opts($qp = null, $text = 0) /* {{{ */
- {
- if ($qp == null) {
- $qp = $this->query_opts;
- }
- $where = array();
- foreach ($qp as $field => $ov) {
- if (is_numeric($field)) {
- $tmp_where = array();
- foreach ($ov as $field2 => $ov2) {
- $tmp_where[] = sprintf('%s %s %s', $field2, $ov2['oper'], $ov2['value']);
- }
- $where[] = '('.join(' OR ', $tmp_where).')';
- } else {
- if (is_array($ov['value'])) {
- $tmp_ov_val = '';
- foreach ($ov['value'] as $ov_val) {
- strlen($tmp_ov_val) > 0 && $tmp_ov_val .= ' OR ';
- $tmp_ov_val .= sprintf('FIND_IN_SET("%s",%s)', $ov_val, $field);
- }
- $where[] = "($tmp_ov_val)";
- } else {
- $where[] = sprintf('%s %s %s', $field, $ov['oper'], $ov['value']);
- }
- }
- }
- // Add any coder specified filters
- if (! $text && $this->filters) {
- $where[] = '('.$this->filters.')';
- }
- if (count($where) > 0) {
- if ($text) {
- return str_replace('%', '*', join(' AND ',$where));
- } else {
- return join(' AND ',$where);
- }
- }
- return false;
- } /* }}} */
- function gather_query_opts() /* {{{ */
- {
- $this->query_opts = array();
- $this->prev_qfn = $this->qfn;
- $this->qfn = '';
- if ($this->clear_operation()) {
- return;
- }
- // gathers query options into an array, $this->query_opts
- $qo = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
- $l = 'qf'.$k;
- $lc = 'qf'.$k.'_comp';
- $li = 'qf'.$k.'_id';
- $m = $this->get_cgi_var($l);
- $mc = $this->get_cgi_var($lc);
- $mi = $this->get_cgi_var($li);
- if (! isset($m) && ! isset($mi)) {
- continue;
- }
- if (is_array($m) || is_array($mi)) {
- if (is_array($mi)) {
- $m = $mi;
- $l = $li;
- }
- if (in_array('*', $m)) {
- continue;
- }
- if ($this->col_has_values($k) && $this->col_has_multiple_select($k)) {
- foreach (array_keys($m) as $key) {
- $m[$key] = addslashes($m[$key]);
- }
- $qo[$this->fqn($k)] = array('value' => $m);
- } else {
- $qf_op = '';
- foreach (array_keys($m) as $key) {
- if ($qf_op == '') {
- $qf_op = 'IN';
- $qf_val = '"'.addslashes($m[$key]).'"';
- $afilter = ' IN ("'.addslashes($m[$key]).'"'; // )
- } else {
- $afilter = $afilter.',"'.addslashes($m[$key]).'"';
- $qf_val .= ',"'.addslashes($m[$key]).'"';
- }
- $this->qfn .= '&'.$l.'['.rawurlencode($key).']='.rawurlencode($m[$key]);
- }
- $afilter = $afilter.')';
- // XXX: $dont_desc and $dont_cols hack
- $dont_desc = isset($this->fdd[$k]['values']['description']);
- $dont_cols = isset($this->fdd[$k]['values']['column']);
- $qo[$this->fqn($k, $dont_desc, $dont_cols)] =
- array('oper' => $qf_op, 'value' => "($qf_val)"); // )
- }
- } else if (isset($mi)) {
- if ($mi == '*') {
- continue;
- }
- if ($this->fdd[$k]['select'] != 'M' && $this->fdd[$k]['select'] != 'D' && $mi == '') {
- continue;
- }
- $afilter = addslashes($mi);
- $qo[$this->fqn($k, true, true)] = array('oper' => '=', 'value' => "'$afilter'");
- $this->qfn .= '&'.$li.'='.rawurlencode($mi);
- } else if (isset($m)) {
- if ($m == '*') {
- continue;
- }
- if ($this->fdd[$k]['select'] != 'M' && $this->fdd[$k]['select'] != 'D' && $m == '') {
- continue;
- }
- $afilter = addslashes($m);
- if ($this->fdd[$k]['select'] == 'N') {
- $mc = in_array($mc, $this->comp_ops) ? $mc : '=';
- $qo[$this->fqn($k)] = array('oper' => $mc, 'value' => "'$afilter'");
- $this->qfn .= '&'.$l .'='.rawurlencode($m);
- $this->qfn .= '&'.$lc.'='.rawurlencode($mc);
- } else {
- $afilter = '%'.str_replace('*', '%', $afilter).'%';
- $ids = array();
- $ar = array();
- $ar[$this->fqn($k)] = array('oper' => 'LIKE', 'value' => "'$afilter'");
- if (is_array($this->fdd[$k]['values2'])) {
- foreach ($this->fdd[$k]['values2'] as $key => $val) {
- if (strlen($m) > 0 && stristr($val, $m)) {
- $ids[] = '"'.addslashes($key).'"';
- }
- }
- if (count($ids) > 0) {
- $ar[$this->fqn($k, true, true)]
- = array('oper' => 'IN', 'value' => '('.join(',', $ids).')');
- }
- }
- $qo[] = $ar;
- $this->qfn .= '&'.$l.'='.rawurlencode($m);
- }
- }
- }
- $this->query_opts = $qo;
- } /* }}} */
- /*
- * Create JavaScripts
- */
- function form_begin() /* {{{ */
- {
- /*
- Need a lot of work in here
- using something like:
- $fdd['fieldname']['validate']['js_regex']='/something/';
- $fdd['fieldname']['validate']['php_regex']='something';
- */
- $page_name = htmlspecialchars($this->page_name);
- if ($this->add_operation() || $this->change_operation() || $this->copy_operation()
- || $this->view_operation() || $this->delete_operation()) {
- $field_to_tab = '';
- for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
- if (isset($this->fdd[$k]['tab'])) {
- if ($tab == 0 && $k > 0) {
- $this->tabs[0] = 'Initial TAB';
- $tab++;
- }
- $this->tabs[$tab] = @$this->fdd[$k]['tab'];
- $tab++;
- }
- $field_to_tab .= max(0, $tab - 1).', ';
- }
- if ($this->tabs_enabled()) {
- // initial TAB styles
- echo '<style type="text/css" media="screen">',"\n";
- echo ' #phpMyEdit_tab0 { display: block; }',"\n";
- for ($i = 1; $i < count($this->tabs); $i++) {
- echo ' #phpMyEdit_tab',$i,' { display: none; }',"\n";
- }
- echo '</style>',"\n";
- // TAB javascripts
- echo '<script type="text/javascript"><!--',"\n\n";
- echo 'var phpMyEdit_field_to_tab = [',$field_to_tab,'-1];',"\n";
- $css_class_name1 = $this->getCSSclass('tab', $position);
- $css_class_name2 = $this->getCSSclass('tab-selected', $position);
- echo 'var phpMyEdit_current_tab = "phpMyEdit_tab0";
- function phpMyEdit_show_tab(tab_name)
- {';
- if ($this->nav_up()) {
- echo '
- document.getElementById(phpMyEdit_current_tab+"_up_label").className = "',$css_class_name1,'";
- document.getElementById(phpMyEdit_current_tab+"_up_link").className = "',$css_class_name1,'";
- document.getElementById(tab_name+"_up_label").className = "',$css_class_name2,'";
- document.getElementById(tab_name+"_up_link").className = "',$css_class_name2,'";';
- }
- if ($this->nav_down()) {
- echo '
- document.getElementById(phpMyEdit_current_tab+"_down_label").className = "',$css_class_name1,'";
- document.getElementById(phpMyEdit_current_tab+"_down_link").className = "',$css_class_name1,'";
- document.getElementById(tab_name+"_down_label").className = "',$css_class_name2,'";
- document.getElementById(tab_name+"_down_link").className = "',$css_class_name2,'";';
- }
- echo '
- document.getElementById(phpMyEdit_current_tab).style.display = "none";
- document.getElementById(tab_name).style.display = "block";
- phpMyEdit_current_tab = tab_name;
- }',"\n\n";
- echo '// --></script>', "\n";
- }
- }
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function phpMyEdit_trim(str)
- {
- while (str.substring(0, 1) == " "
- || str.substring(0, 1) == "\\n"
- || str.substring(0, 1) == "\\r")
- {
- str = str.substring(1, str.length);
- }
- while (str.substring(str.length - 1, str.length) == " "
- || str.substring(str.length - 1, str.length) == "\\n"
- || str.substring(str.length - 1, str.length) == "\\r")
- {
- str = str.substring(0, str.length - 1);
- }
- return str;
- }
- function phpMyEdit_form_control(theForm)
- {',"\n";
- if ($this->add_operation() || $this->change_operation() || $this->copy_operation()) {
- $required_ar = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
- if ($this->displayed[$k] && $this->fdd[$k]['required']
- && ! $this->readonly($k) && ! $this->hidden($k)) {
- $required_ar[] = $k;
- if (isset($this->fdd[$k]['regex']['js'])) {
- /* TODO: Use a javascript regex to validate it */
- }
- }
- }
- if (count($required_ar) > 0) {
- foreach ($required_ar as $field_num) {
- if ($this->col_has_values($field_num)) {
- $condition = 'theForm.%s.selectedIndex == -1';
- $multiple = $this->col_has_multiple_select($field_num);
- } else {
- $condition = 'phpMyEdit_trim(theForm.%s.value) == ""';
- $multiple = false;
- }
- /* Multiple selects have their name like ``name[]''.
- It is not possible to work with them directly, because
- theForm.name[].something will result into JavaScript
- syntax error. Following search algorithm is provided
- as a workaround for this.
- */
- if ($multiple) {
- echo '
- multiple_select = null;
- for (i = 0; i < theForm.length; i++) {
- if (theForm.elements[i].name == "',$this->fds[$field_num],'[]") {
- multiple_select = theForm.elements[i];
- break;
- }
- }
- if (multiple_select != null && multiple_select.selectedIndex == -1) {
- alert("',$this->labels['Please enter'],' ',$this->fdd[$field_num]['name'],'.");';
- if ($this->tabs_enabled()) {
- echo '
- phpMyEdit_show_tab("phpMyEdit_tab"+phpMyEdit_field_to_tab['.$field_num.']);';
- }
- echo '
- return false;
- }',"\n";
- } else {
- echo '
- if (',sprintf($condition, $this->fds[$field_num]),') {
- alert("',$this->labels['Please enter'],' ',$this->fdd[$field_num]['name'],'.");';
- if ($this->tabs_enabled()) {
- echo '
- phpMyEdit_show_tab("phpMyEdit_tab"+phpMyEdit_field_to_tab['.$field_num.']);';
- }
- echo '
- theForm.',$this->fds[$field_num],'.focus();
- return false;
- }',"\n";
- }
- }
- }
- }
- echo '
- return true;
- }',"\n\n";
- echo '// --></script>', "\n";
- global $smarty;
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function newmail()
- {
- this.location.href("mailto:?body="
- +"Betrieb:%20"+document.phpMyEdit_form.Betrieb.value+"%0A"
- +"Abteilung:%20"+document.phpMyEdit_form.Stufe2.value+"%0A"
- +"Verkäufer:%20"+document.phpMyEdit_form.Stufe5.value+"%0A"
- +"FG.-Nummer:%20"+document.phpMyEdit_form.FAGNR.value+"%0A%0A"
- +"Kunde:%0A"+document.phpMyEdit_form.KNAME.value+"%0A%0A"
- +"Belegnummer:%20"+document.phpMyEdit_form.O500_BELEGNR1.value+"%0A"
- +"Rechnungsbetrag:%20"+document.phpMyEdit_form.O500_HW2BUCHGBETR.value+"%0A"
- +"Offener Betrag:%20"+document.phpMyEdit_form.O500_HW2BETR_OFFEN.value+"%0A");
- }',"\n\n";
- echo '// --></script>', "\n";
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function opendoc()
- {
- var formular = document.phpMyEdit_form;
- doc = window.open("rtf/rtf_beitreibungsauftrag.php?report=' . $_SERVER["PHP_SELF"] .
- '&KNAME="+encodeURIComponent(formular.KNAME.value)
- +"&KNDNR="+encodeURIComponent(formular.KNDNR.value)
- +"&Kstra="+encodeURIComponent(formular.Kstra.value)
- +"&Kdplz="+encodeURIComponent(formular.Kdplz.value)
- +"&Kdort="+encodeURIComponent(formular.Kdort.value)
- +"&Ktelf="+formular.Ktelf.value
- +"&BelNr="+formular.O500_BELEGNR1.value
- +"&ReDat="+formular.REDAT.value
- +"&Verka="+encodeURIComponent(formular.Stufe5.value)
- +"&Betri="+encodeURIComponent(formular.Betrieb.value + " - " + formular.Stufe2.value)
- +"&OffBe="+formular.O500_HW2BETR_OFFEN.value
- +"&RechBe="+formular.O500_HW2BUCHGBETR.value
- +"&Mahnst="+encodeURIComponent(formular.O500_MAHNSTUFE.value)
- +"&NextMahnst="+formular.Next_MAHNSTUFE.value, "Dokument");
- doc.focus;
- }',"\n\n";
- echo '// --></script>', "\n";
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function overview()
- {
- rtf = window.open("rtf/rtf_over.php?report=' . $_SERVER["PHP_SELF"] .
- '&Betrieb=' . urlencode($_POST["betr"]) . '&Stufe2=' . urlencode($_POST["stufe_2"]) .
- '&Stufe5=' . urlencode($_POST["stufe_5"]) .
- '&Mahnstufe=' . urlencode($_POST["mahnst"]) .
- '&from=' . $_POST["datefrom"] . '&until=' . $_POST["dateuntil"] .
- '&Kunde=' . urlencode($_POST["k_name"]) .
- '&Reklamation=' . $_POST["rekl"] .
- '&Versicherung=' . $_POST["vers"] .
- '&Rechtsanwalt=' . @$_POST["ra"] .
- '&wv=' . $_POST["Wiedervorl"] .
- '&Mahnen=' . $_POST["Mahnen_ent"] .
- '&Reserve_3=' . $_POST["rechgut"] .
- '&Wochen=' . urlencode($_POST["woch"]) . '", "RTF");
- rtf.focus();
- }',"\n\n";
- echo '// --></script>', "\n";
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function ticker()
- {
- rtf = window.open("rtf/rtf_ticker.php?report=' . $_SERVER["PHP_SELF"] .
- '&fgst="+document.phpMyEdit_form.Fgst.value+"&modell="+document.phpMyEdit_form.Modell.value
- +"&version="+document.phpMyEdit_form.Version.value
- +"&ps="+document.phpMyEdit_form.KW_PS.value
- +"&motor="+document.phpMyEdit_form.Motor.value
- +"&farbe="+document.phpMyEdit_form.Farbe.value
- +"&farbedet="+document.phpMyEdit_form.Farbe_detail.value
- +"&polster="+document.phpMyEdit_form.Polsterung.value
- +"&km="+document.phpMyEdit_form.Letzter_KM.value
- +"&vkbrutto="+document.phpMyEdit_form.VK_Brutto.value
- +"&optdet="+document.phpMyEdit_form.Optionen.value
- +"&ez="+document.phpMyEdit_form.EZ.value, "RTF");
- rtf.focus();
- }',"\n\n";
- echo '// --></script>', "\n";
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function accessor()
- {
- acc = window.open("rtf/rtf_accessories.php?report=' . $_SERVER["PHP_SELF"] .
- '&modell="+document.phpMyEdit_form.Modell.value
- +"&farbe="+document.phpMyEdit_form.Farbe.value
- +"&farbedet="+document.phpMyEdit_form.Farbe_detail.value
- +"&polster="+document.phpMyEdit_form.Polsterung.value
- +"&vkbrutto="+document.phpMyEdit_form.VK_Brutto.value
- +"&optdet="+document.phpMyEdit_form.Optionen.value, "Accessories");
- acc.focus();
- }',"\n\n";
- echo '// --></script>', "\n";
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function leasing_off()
- {
- leas = window.open("rtf/rtf_leasing_offer.php?report=' . $_SERVER["PHP_SELF"] . '", "RTF");
- leas.focus();
- }',"\n\n";
- echo '// --></script>', "\n";
- /*
- * Statt der for-Schleife, die ja net geht, eine while-Schleife benutzen.
- * jedes Mal prüfen, wie groß die Menge der UPE_Netto[n] ist, wenn 0, dann Abbruch
- * i nach jedem Durchlauf hochzählen.
- *
- * Was ist, wenn die Seite in Tabs eingeteilt ist, sprich select_goto aktiv ist?!
- */
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function change_input()
- {
- var confirmed = 0;
- var cancel = 0;
- var i = 1;
- var v1, v2, value = 0;
- if (document.getElementsByName("VK_Netto_change")[0].value != "") {
- if ( confirmed == 0 ) {
- Check = confirm("Haben sie ihre Eingabe überprüft?");
- }
- if (Check == false) abort;
- while (cancel == 0) {
- if (document.getElementsByName("VK_Netto["+i+"]").length == 1){
- if ( document.getElementsByName("VK_Netto_change")[0].value.substr(document.getElementsByName("VK_Netto_change")[0].value.length-1,1) == "%" ){
- if ( document.getElementsByName("VK_Netto_change")[0].value.substr(0,1) == "-" ){
- v1 = parseFloat(document.getElementsByName("VK_Netto["+i+"]")[0].value);
- v2 = 0.01*parseFloat(document.getElementsByName("VK_Netto_change")[0].value.substr(1,document.getElementsByName("VK_Netto_change")[0].value.length-1));
- if ( v2 > 1 ) {
- alert("Man kann den Preis nicht um mehr als 100% verringern!");
- break;
- }
- value = v1-(v2*v1);
- document.getElementsByName("VK_Netto["+i+"]")[0].value = eval(value);
- } else if ( document.getElementsByName("VK_Netto_change")[0].value.substr(0,1) == "+" ){
- v1 = parseFloat(document.getElementsByName("VK_Netto["+i+"]")[0].value);
- v2 = 0.01*parseFloat(document.getElementsByName("VK_Netto_change")[0].value.substr(1,document.getElementsByName("VK_Netto_change")[0].value.length-1));
- value = v1 + (v2*v1);
- document.getElementsByName("VK_Netto["+i+"]")[0].value = eval(value);
- }
- } else if ( document.getElementsByName("VK_Netto_change")[0].value.substr(0,1) == "-" ){
- v1 = parseFloat(document.getElementsByName("VK_Netto["+i+"]")[0].value);
- v2 = parseFloat(document.getElementsByName("VK_Netto_change")[0].value.substr(1,document.getElementsByName("VK_Netto_change")[0].value.length));
- if ( v2 > v1 ) {
- alert("Ein Preis kleiner als 0 ist nicht sinnvoll!");
- break;
- }
- value = v1 - v2;
- document.getElementsByName("VK_Netto["+i+"]")[0].value = eval(value);
- } else if ( document.getElementsByName("VK_Netto_change")[0].value.substr(0,1) == "+" ){
- v1 = parseFloat(document.getElementsByName("VK_Netto["+i+"]")[0].value);
- v2 = parseFloat(document.getElementsByName("VK_Netto_change")[0].value.substr(1,document.getElementsByName("VK_Netto_change")[0].value.length));
- value = v1 + v2;
- document.getElementsByName("VK_Netto["+i+"]")[0].value = eval(value);
- } else {
- document.getElementsByName("VK_Netto["+i+"]")[0].value = document.getElementsByName("VK_Netto_change")[0].value;
- }
- } else {
- cancel = 1;
- }
- i++;
- }
- }
- }',"\n\n";
- echo '// --></script>', "\n";
- /*
- $part = substr($_SERVER['SCRIPT_NAME'], strpos($_SERVER['SCRIPT_NAME'], "/")+1);
- $strDoc = '';
- $strDoc = file_get_contents(substr($part, strpos($part, "/")+1));
- $match = substr($strDoc, strpos($strDoc, 'reportName')+14);
- $match = substr($match, 0, strpos($match, ';')-1);
- */
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function detail()
- {
- var adresse = "rtf/rtf_detail.php?report=' . $_SERVER["PHP_SELF"] . '&";
- for (i=0; i < document.getElementsByTagName("input").length; i++) {
- if ( document.getElementsByTagName("input")[i].type == "text" ) {
- adresse = adresse + document.getElementsByTagName("input")[i].name + "=" + encodeURIComponent(document.getElementsByTagName("input")[i].value) + "&";
- <!--alert(adresse);-->
- }
- }
- for (i=0; i < document.getElementsByTagName("select").length; i++) {
- adresse = adresse + document.getElementsByTagName("select")[i].name + "=" + encodeURIComponent(document.getElementsByTagName("select")[i].value) + "&";
- <!--alert(adresse);-->
- }
- for (i=0; i < document.getElementsByTagName("textarea").length; i++) {
- adresse = adresse + document.getElementsByTagName("textarea")[i].name + "=" + encodeURIComponent(document.getElementsByTagName("textarea")[i].value) + "&";
- <!--alert(adresse);-->
- }
- rtf = window.open(adresse, "RTF");
- rtf.focus();
- }',"\n\n";
- echo '// --></script>', "\n";
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function pdf_detail()
- {
- doc = window.open("pdf_detail.php?KNAME="+document.phpMyEdit_form.KNAME.value
- +"&Kstra="+document.phpMyEdit_form.Kstra.value
- +"&Kdplz="+document.phpMyEdit_form.Kdplz.value
- +"&Kdort="+document.phpMyEdit_form.Kdort.value
- +"&Ktelf="+document.phpMyEdit_form.Ktelf.value
- +"&BelNr="+document.phpMyEdit_form.O500_BELEGNR1.value
- +"&ReDat="+document.phpMyEdit_form.REDAT.value
- +"&Verka="+document.phpMyEdit_form.Stufe5.value
- +"&Betri="+document.phpMyEdit_form.Betrieb.value+" - "+document.phpMyEdit_form.Stufe2.value
- +"&OffBe="+document.phpMyEdit_form.O500_HW2BETR_OFFEN.value
- +"&RechBe="+document.phpMyEdit_form.O500_HW2BUCHGBETR.value
- +"&Mahnst="+document.phpMyEdit_form.O500_MAHNSTUFE.value, "pdf");
- doc.focus;
- }',"\n\n";
- echo '// --></script>', "\n";
- if ($this->filter_operation()) {
- echo '<script type="text/javascript"><!--',"\n";
- echo '
- function phpMyEdit_filter_handler(theForm, theEvent)
- {
- var pressed_key = null;
- if (theEvent.which) {
- pressed_key = theEvent.which;
- } else {
- pressed_key = theEvent.keyCode;
- }
- if (pressed_key == 13) { // enter pressed
- theForm.submit();
- return false;
- }
- return true;
- }',"\n\n";
- echo '// --></script>', "\n";
- }
- if ($this->display['form']) {
- echo '<form class="',$this->getCSSclass('form'),'" method="POST"';
- echo ' action="',$page_name,'" onSubmit="return dateFormatEdit();" name="phpMyEdit_form">',"\n";
- }
- return true;
- } /* }}} */
- function form_end() /* {{{ */
- {
- if ($this->display['form']) {
- echo '</form>',"\n";
- }
- } /* }}} */
- function display_tab_labels($position) /* {{{ */
- {
- if (! is_array($this->tabs)) {
- return false;
- }
- echo '<table class="',$this->getCSSclass('tab', $position),'">',"\n";
- echo '<tr class="',$this->getCSSclass('tab', $position),'">',"\n";
- for ($i = 0; $i < count($this->tabs); $i++) {
- $css_class_name = $this->getCSSclass($i ? 'tab' : 'tab-selected', $position);
- echo '<td class="',$css_class_name,'" id="phpMyEdit_tab',$i,'_',$position,'_label">';
- echo '<a class="',$css_class_name,'" id="phpMyEdit_tab',$i,'_',$position,'_link';
- echo '" href="javascript:phpMyEdit_show_tab(\'phpMyEdit_tab',$i,'\')">';
- echo $this->tabs[$i],'</a></td>',"\n";
- }
- echo '<td class="',$this->getCSSclass('tab-end', $position),'"> </td>',"\n";
- echo '</tr>',"\n";
- echo '</table>',"\n";
- } /* }}} */
- /*
- * Display functions
- */
- function display_add_record() /* {{{ */
- {
- global $smarty;
- for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
- if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
- $tab++;
- #echo '</table>',"\n";
- #echo '</div>',"\n";
- #echo '<div id="phpMyEdit_tab',$tab,'">',"\n";
- #echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
- }
- if (! $this->displayed[$k]) {
- continue;
- }
- if ($this->hidden($k)) {
- $htmlHidden = $this->htmlHidden($this->fds[$k], $this->fdd[$k]['default']);
- $smarty->append("form_hidden", $htmlHidden);
- continue;
- }
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- $css_class_name = $this->getCSSclass('input', null, 'next', $css_postfix);
- #echo '<tr class="',$this->getCSSclass('row', null, true, $css_postfix),'">',"\n";
- #echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n";
- #echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
- #echo $this->getColAttributes($k),">\n";
- $smarty->assign($this->fds[$k]."Txt", $this->fdd[$k]['name']);
- if ($this->col_has_values($k)) {
- $vals = $this->set_values($k);
- $selected = @$this->fdd[$k]['default'];
- $multiple = $this->col_has_multiple_select($k);
- $readonly = $this->readonly($k);
- $strip_tags = true;
- $escape = true;
- $htmlSelect = $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $selected,
- $multiple, $readonly, $strip_tags, $escape);
- $smarty->assign($this->fds[$k]."Val", $htmlSelect);
- } elseif (isset ($this->fdd[$k]['textarea'])) {
- ob_start();
- echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"';
- echo ($this->readonly($k) ? ' disabled' : '');
- if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
- echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
- }
- if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
- echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
- }
- if (isset($this->fdd[$k]['textarea']['wrap'])) {
- echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
- } else {
- echo ' wrap="virtual"';
- }
- echo '>',htmlspecialchars($this->fdd[$k]['default']),'</textarea>',"\n";
- $smarty->assign($this->fds[$k]."Val", ob_get_contents());
- ob_end_clean();
- } else {
- ob_start();
- // Simple edit box required
- $size_ml_props = '';
- $maxlen = intval($this->fdd[$k]['maxlen']);
- $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
- $size && $size_ml_props .= ' size="'.$size.'"';
- $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
- echo '<input class="',$css_class_name,'" type="text" ';
- echo ($this->readonly($k) ? 'disabled ' : ''),' name="',$this->fds[$k],'"';
- echo $size_ml_props,' value="';
- echo htmlspecialchars($this->fdd[$k]['default']),'">';
- $smarty->assign($this->fds[$k]."Val", ob_get_contents());
- ob_end_clean();
- }
- #echo '</td>',"\n";
- if ($this->guidance) {
- $css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
- $cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' ';
- #echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
- }
- #echo '</tr>',"\n";
- }
- } /* }}} */
- function display_copy_change_delete_record() /* {{{ */
- {
- global $smarty;
- /*
- * For delete or change: SQL SELECT to retrieve the selected record
- */
- $qparts['type'] = 'select';
- $qparts['select'] = $this->create_column_list();
- $qparts['from'] = $this->create_join_clause();
- $qparts['where'] = '('.$this->fqn($this->key).'='
- .$this->key_delim.$this->rec.$this->key_delim.')';
- $res = $this->myquery($this->query_make($qparts),__LINE__);
- if (! ($row = @mysql_fetch_array($res, MYSQL_ASSOC))) {
- return false;
- }
- $xrow = array();
- for ($tab = 0, $k = 0; $k < $this->num_fds; $k++) {
- $xrow[$this->fds[$k]] = $row["qf$k"];
- if (isset($this->fdd[$k]['tab']) && $this->tabs_enabled() && $k > 0) {
- $tab++;
- #echo '</table>',"\n";
- #echo '</div>',"\n";
- #echo '<div id="phpMyEdit_tab',$tab,'">',"\n";
- #echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
- }
- if (! $this->displayed[$k]) {
- continue;
- }
- if ($this->copy_operation() || $this->change_operation()) {
- if ($this->hidden($k)) {
- if ($k != $this->key_num) {
- $htmlHidden = $this->htmlHidden($this->fds[$k], $row["qf$k"]);
- $smarty->append("form_hidden", $htmlHidden);
- }
- continue;
- }
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- #echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
- #echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n";
- $smarty->assign($this->fds[$k]."Txt", $this->fdd[$k]['name']);
- /* There are two possibilities of readonly fields handling:
- 1. Display plain text for readonly timestamps and dates.
- 2. Display disabled input field
- In all cases particular readonly field will NOT be saved. */
- ob_start();
- if ($this->col_has_datemask($k) && $this->readonly($k)) {
- echo $this->display_delete_field($row, $k);
- } elseif ($this->password($k)) {
- echo $this->display_password_field($row, $k);
- } else {
- echo $this->display_change_field($row, $k);
- }
- $smarty->assign($this->fds[$k]."Val", ob_get_contents());
- ob_end_clean();
- if ($this->guidance) {
- $css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
- $cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' ';
- #echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
- }
- #echo '</tr>',"\n";
- } elseif ($this->delete_operation() || $this->view_operation()) {
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- #echo '<tr class="',$this->getCSSclass('row', null, 'next', $css_postfix),'">',"\n";
- #echo '<td class="',$this->getCSSclass('key', null, true, $css_postfix),'">',$this->fdd[$k]['name'],'</td>',"\n";
- $smarty->assign($this->fds[$k]."Txt", $this->fdd[$k]['name']);
- ob_start();
- if ($this->password($k)) {
- #echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
- #echo $this->getColAttributes($k),'>',$this->labels['hidden'],'</td>',"\n";
- echo $this->labels['hidden'];
- } else {
- $this->display_delete_field($row, $k);
- }
- $smarty->assign($this->fds[$k]."Val", ob_get_contents());
- ob_end_clean();
- if ($this->guidance) {
- $css_class_name = $this->getCSSclass('help', null, true, $css_postfix);
- $cell_value = $this->fdd[$k]['help'] ? $this->fdd[$k]['help'] : ' ';
- #echo '<td class="',$css_class_name,'">',$cell_value,'</td>',"\n";
- }
- #echo '</tr>',"\n";
- }
- }
- $smarty->assign('rows', $xrow);
- } /* }}} */
- function display_change_field($row, $k) /* {{{ */
- {
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- $css_class_name = $this->getCSSclass('input', null, true, $css_postfix);
- #echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
- #echo $this->getColAttributes($k),">\n";
- if ($this->col_has_values($k)) {
- $vals = $this->set_values($k);
- $multiple = $this->col_has_multiple_select($k);
- $readonly = $this->readonly($k);
- $strip_tags = true;
- $escape = true;
- echo $this->htmlSelect($this->fds[$k], $css_class_name, $vals, $row["qf$k"],
- $multiple, $readonly, $strip_tags, $escape);
- } elseif (isset($this->fdd[$k]['textarea'])) {
- echo '<textarea class="',$css_class_name,'" name="',$this->fds[$k],'"';
- echo ($this->readonly($k) ? ' disabled' : '');
- if (intval($this->fdd[$k]['textarea']['rows']) > 0) {
- echo ' rows="',$this->fdd[$k]['textarea']['rows'],'"';
- }
- if (intval($this->fdd[$k]['textarea']['cols']) > 0) {
- echo ' cols="',$this->fdd[$k]['textarea']['cols'],'"';
- }
- if (isset($this->fdd[$k]['textarea']['wrap'])) {
- echo ' wrap="',$this->fdd[$k]['textarea']['wrap'],'"';
- } else {
- echo ' wrap="virtual"';
- }
- echo '>',htmlspecialchars($row["qf$k"]),'</textarea>',"\n";
- } else {
- $size_ml_props = '';
- $maxlen = intval($this->fdd[$k]['maxlen']);
- $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
- $size && $size_ml_props .= ' size="'.$size.'"';
- $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
- echo '<input class="',$css_class_name,'" type="text" ';
- echo ($this->readonly($k) ? 'disabled ' : ''),'name="',$this->fds[$k],'" value="';
- echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n";
- }
- #echo '</td>',"\n";
- } /* }}} */
- function display_password_field($row, $k) /* {{{ */
- {
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- #echo '<td class="',$this->getCSSclass('value', null, true, $css_postfix),'"';
- #echo $this->getColAttributes($k),">\n";
- $size_ml_props = '';
- $maxlen = intval($this->fdd[$k]['maxlen']);
- $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size'] : min($maxlen, 60);
- $size && $size_ml_props .= ' size="'.$size.'"';
- $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
- echo '<input class="',$this->getCSSclass('value', null, true, $css_postfix),'" type="password" ';
- echo ($this->readonly($k) ? 'disabled ' : ''),'name="',$this->fds[$k],'" value="';
- echo htmlspecialchars($row["qf$k"]),'" ',$size_ml_props,'>',"\n";
- #echo '</td>',"\n";
- } /* }}} */
- function display_delete_field($row, $k) /* {{{ */
- {
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- $css_class_name = $this->getCSSclass('value', null, true, $css_postfix);
- #echo '<td class="',$css_class_name,'"',$this->getColAttributes($k),">\n";
- echo $this->cellDisplay($k, $row, $css_class_name);
- #echo '</td>',"\n";
- } /* }}} */
- /**
- * Returns CSS class name
- */
- function getCSSclass($name, $position = null, $divider = null, $postfix = null) /* {{{ */
- {
- static $div_idx = -1;
- $elements = array($this->css['prefix'], $name);
- if ($this->page_type && $this->css['page_type']) {
- if ($this->page_type != 'L' && $this->page_type != 'F') {
- $elements[] = $this->page_types[$this->page_type];
- }
- }
- if ($position && $this->css['position']) {
- $elements[] = $position;
- }
- if ($divider && $this->css['divider']) {
- if ($divider === 'next') {
- $div_idx++;
- if ($this->css['divider'] > 0 && $div_idx >= $this->css['divider']) {
- $div_idx = 0;
- }
- }
- $elements[] = $div_idx;
- }
- if ($postfix) {
- $elements[] = $postfix;
- }
- return join($this->css['separator'], $elements);
- } /* }}} */
- /**
- * Returns field cell HTML attributes
- */
- function getColAttributes($k) /* {{{ */
- {
- $colattrs = '';
- if (isset($this->fdd[$k]['colattrs'])) {
- $colattrs .= ' ';
- $colattrs .= trim($this->fdd[$k]['colattrs']);
- }
- if (isset($this->fdd[$k]['nowrap'])) {
- $colattrs .= ' nowrap';
- }
- return $colattrs;
- } /* }}} */
- /**
- * Substitutes variables in string
- * (this is very simple but secure eval() replacement)
- */
- function substituteVars($str, $subst_ar) /* {{{ */
- {
- $array = preg_split('/\\$(\w+)/', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
- for ($i = 1; $i < count($array); $i += 2) {
- if (isset($subst_ar[$array[$i]]))
- $array[$i] = $subst_ar[$array[$i]];
- }
- return join('', $array);
- } /* }}} */
- /**
- * Print URL
- */
- function urlDisplay($k, $link_val, $disp_val, $css, $key) /* {{{ */
- {
- $ret = '';
- $name = $this->fds[$k];
- $page = $this->page_name;
- $url = 'rec='.$key.'&fm='.$this->fm.'&fl='.$this->fl;
- $url .= '&qfn='.rawurlencode($this->qfn).$this->qfn;
- $url .= '&'.$this->get_sfn_cgi_vars().$this->cgi['persist'];
- $ar = array(
- 'key' => $key,
- 'name' => $name,
- 'link' => $link_val,
- 'value' => $disp_val,
- 'css' => $css,
- 'page' => $page,
- 'url' => $url
- );
- $urllink = isset($this->fdd[$k]['URL'])
- ? $this->substituteVars($this->fdd[$k]['URL'], $ar)
- : $link_val;
- $urldisp = isset($this->fdd[$k]['URLdisp'])
- ? $this->substituteVars($this->fdd[$k]['URLdisp'], $ar)
- : $disp_val;
- $target = isset($this->fdd[$k]['URLtarget'])
- ? 'target="'.htmlspecialchars($this->fdd[$k]['URLtarget']).'" '
- : '';
- $prefix_found = false;
- $postfix_found = false;
- $prefix_ar = @$this->fdd[$k]['URLprefix'];
- $postfix_ar = @$this->fdd[$k]['URLpostfix'];
- is_array($prefix_ar) || $prefix_ar = array($prefix_ar);
- is_array($postfix_ar) || $postfix_ar = array($postfix_ar);
- foreach ($prefix_ar as $prefix) {
- if (! strncmp($prefix, $urllink, strlen($prefix))) {
- $prefix_found = true;
- break;
- }
- }
- foreach ($postfix_ar as $postfix) {
- if (! strncmp($postfix, $urllink, strlen($postfix))) {
- $postfix_found = true;
- break;
- }
- }
- $prefix_found || $urllink = array_shift($prefix_ar).$urllink;
- $postfix_found || $urllink = $urllink.array_shift($postfix_ar);
- if (strlen($urllink) <= 0 || strlen($urldisp) <= 0) {
- $ret = ' ';
- } else {
- $urllink = htmlspecialchars($urllink);
- $urldisp = htmlspecialchars($urldisp);
- $ret = '<a '.$target.'class="'.$css.'" href="'.$urllink.'">'.$urldisp.'</a>';
- }
- return $ret;
- } /* }}} */
- function cellDisplay($k, $row, $css) /* {{{ */
- {
- $escape = isset($this->fdd[$k]['escape']) ? $this->fdd[$k]['escape'] : true;
- $key_rec = $row['qf'.$this->key_num];
- if (@$this->fdd[$k]['datemask']) {
- $value = intval($row["qf$k".'_timestamp']);
- $value = $value ? @date($this->fdd[$k]['datemask'], $value) : '';
- } else if (@$this->fdd[$k]['strftimemask']) {
- $value = intval($row["qf$k".'_timestamp']);
- $value = $value ? @strftime($this->fdd[$k]['strftimemask'], $value) : '';
- } else if ($this->is_values2($k, $row["qf$k"])) {
- $value = $row['qf'.$k.'_idx'];
- if ($this->fdd[$k]['select'] == 'M') {
- $value_ar = explode(',', $value);
- $value_ar2 = array();
- foreach ($value_ar as $value_key) {
- if (isset($this->fdd[$k]['values2'][$value_key])) {
- $value_ar2[$value_key] = $this->fdd[$k]['values2'][$value_key];
- $escape = false;
- }
- }
- $value = join(', ', $value_ar2);
- } else {
- if (isset($this->fdd[$k]['values2'][$value])) {
- $value = $this->fdd[$k]['values2'][$value];
- $escape = false;
- }
- }
- } else {
- $value = $row["qf$k"];
- }
- $original_value = $value;
- if (@$this->fdd[$k]['strip_tags']) {
- $value = strip_tags($value);
- }
- if (intval($this->fdd[$k]['trimlen']) > 0 && strlen($value) > $this->fdd[$k]['trimlen']) {
- $value = ereg_replace("[\r\n\t ]+",' ',$value);
- $value = substr($value, 0, $this->fdd[$k]['trimlen'] - 3).'...';
- }
- if (@$this->fdd[$k]['mask']) {
- $value = sprintf($this->fdd[$k]['mask'], $value);
- }
- if (isset($this->fdd[$k]['eval'])) {
- eval($this->fdd[$k]['eval']);
- }
- if ($this->col_has_URL($k)) {
- return $this->urlDisplay($k, $original_value, $value, $css, $key_rec);
- }
- if (strlen($value) <= 0) {
- return ' ';
- }
- if ($escape) {
- $value = htmlspecialchars($value);
- }
- return nl2br($value);
- } /* }}} */
- /**
- * Creates HTML submit input element
- *
- * @param name element name
- * @param label key in the language hash used as label
- * @param css_class_name CSS class name
- * @param js_validation if add JavaScript validation subroutine to button
- * @param disabled if mark the button as disabled
- */
- function htmlSubmit($name, $label, $css_class_name, $js_validation = true, $disabled = false) /* {{{ */
- {
- // Note that <input disabled> isn't valid HTML, but most browsers support it
- $markdisabled = $disabled ? ' disabled' : '';
- $ret = '<input'.$markdisabled.' type="submit" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- if ($name == 'mailchange'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=newmail() "';
- }
- else if ($name == 'docchange'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=opendoc() "';
- }
- else if ($name == 'rtfgen'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=overview() "';
- }
- else if ($name == 'adminchange'){
- $ret = '<input'.$markdisabled.' type="submit" class="'.$css_class_name
- .'" name="adminchange'
- .'" value="'.__('Save');
- $ret .= '" onClick="change_input();" "';
- }
- else if ($name == 'rtfgen_detail'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=detail() "';
- }
- else if ($name == 'rtfgen_ticker'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=ticker() "';
- }
- else if ($name == 'rtfgen_ticker_all'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=ticker_all() "';
- }
- else if ($name == 'leasing_offer'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=leasing_off() "';
- }
- else if ($name == 'accessories'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" onClick=accessor() "';
- }
- else if ($name == 'execute'){
- $ret = '<input'.$markdisabled.' type="button" class="'.$css_class_name
- .'" name="'.ltrim($markdisabled).$name
- .'" value="'.__(isset($this->labels[$label]) ? $this->labels[$label] : $label);
- $ret .= '" "';
- }
- else if ($js_validation) {
- $ret .= '" onClick="return phpMyEdit_form_control(this.form);';
- }
- $ret .= '">';
- return $ret;
- } /* }}} */
- /**
- * Creates HTML hidden input element
- *
- * @param name element name
- * @param value value
- */
- function htmlHidden($name, $value) /* {{{ */
- {
- return '<input type="hidden" name="'.htmlspecialchars($name)
- .'" value="'.htmlspecialchars($value).'">'."\n";
- } /* }}} */
- /**
- * Creates HTML select element (tag)
- *
- * @param name element name
- * @param css CSS class name
- * @param kv_array key => value array
- * @param selected selected key (it can be single string, array of
- * keys or multiple values separated by comma)
- * @param multiple bool for multiple selection
- * @param readonly bool for readonly/disabled selection
- * @param strip_tags bool for stripping tags from values
- * @param escape bool for HTML escaping values
- */
- function htmlSelect($name, $css, $kv_array, $selected = null, /* ...) {{{ */
- /* booleans: */ $multiple = false, $readonly = false, $strip_tags = false, $escape = true)
- {
- $ret = '<select class="'.htmlspecialchars($css).'" name="'.htmlspecialchars($name);
- if ($multiple) {
- $ret .= '[]" multiple size="'.$this->multiple;
- if (! is_array($selected) && $selected !== null) {
- $selected = explode(',', $selected);
- }
- }
- $ret .= '"'.($readonly ? ' disabled' : '').'>'."\n";
- if (! is_array($selected)) {
- $selected = $selected === null ? array() : array($selected);
- }
- $found = false;
- foreach ($kv_array as $key => $value) {
- $ret .= '<option value="'.htmlspecialchars($key).'"';
- if ((! $found || $multiple) && in_array((string) $key, $selected, 1)
- || (count($selected) == 0 && ! $found && ! $multiple)) {
- $ret .= ' selected';
- $found = true;
- }
- $strip_tags && $value = strip_tags($value);
- $escape && $value = htmlspecialchars($value);
- $ret .= '>'.$value.'</option>'."\n";
- }
- $ret .= '</select>';
- return $ret;
- } /* }}} */
- /**
- * Returns original variables HTML code for use in forms or links.
- *
- * @param mixed $origvars string or array of original varaibles
- * @param string $method type of method ("POST" or "GET")
- * @param mixed $default_value default value of variables
- * if null, empty values will be skipped
- * @return get HTML code of original varaibles
- */
- function get_origvars_html($origvars, $method = 'POST', $default_value = '') /* {{{ */
- {
- $ret = '';
- $method = strtoupper($method);
- if ($method == 'POST') {
- if (! is_array($origvars)) {
- $new_origvars = array();
- foreach (explode('&', $origvars) as $param) {
- $parts = explode('=', $param, 2);
- if (! isset($parts[1])) {
- $parts[1] = $default_value;
- }
- if (strlen($parts[0]) <= 0) {
- continue;
- }
- $new_origvars[$parts[0]] = $parts[1];
- }
- $origvars =& $new_origvars;
- }
- foreach ($origvars as $key => $val) {
- if (strlen($val) <= 0 && $default_value === null) {
- continue;
- }
- $key = rawurldecode($key);
- $val = rawurldecode($val);
- $ret .= '<input type="hidden" name="';
- $ret .= htmlspecialchars($key).'"';
- $ret .= ' value="'.htmlspecialchars($val).'"';
- $ret .= " />\n";
- }
- } else if (! strncmp('GET', $method, 3)) {
- if (! is_array($origvars)) {
- $ret .= $origvars;
- } else {
- foreach ($origvars as $key => $val) {
- if (strlen($val) <= 0 && $default_value === null) {
- continue;
- }
- $ret == '' || $ret .= '&';
- $ret .= htmlspecialchars(rawurlencode($key));
- $ret .= '=';
- $ret .= htmlspecialchars(rawurlencode($val));
- }
- }
- if ($method[strlen($method) - 1] == '+') {
- $ret = "?$ret";
- }
- } else {
- trigger_error('Unsupported Platon::get_origvars_html() method: '
- .$method, E_USER_ERROR);
- }
- return $ret;
- } /* }}} */
- function get_sfn_cgi_vars($alternative_sfn = null) /* {{{ */
- {
- if ($alternative_sfn === null) { // FAST! (cached return value)
- static $ret = null;
- $ret == null && $ret = $this->get_sfn_cgi_vars($this->sfn);
- return $ret;
- }
- $ret = '';
- $i = 0;
- foreach ($alternative_sfn as $val) {
- $ret != '' && $ret .= '&';
- $ret .= "sfn[$i]=".rawurlencode($val);
- $i++;
- }
- return $ret;
- } /* }}} */
- function get_cgi_var($name, $default_value = null) /* {{{ */
- {
- if (isset($this) && isset($this->cgi['overwrite'][$name])) {
- return $this->cgi['overwrite'][$name];
- }
- static $magic_quotes_gpc = null;
- if ($magic_quotes_gpc === null) {
- $magic_quotes_gpc = get_magic_quotes_gpc();
- }
- global $HTTP_GET_VARS;
- $var = @$HTTP_GET_VARS[$name];
- if (! isset($var)) {
- global $HTTP_POST_VARS;
- $var = @$HTTP_POST_VARS[$name];
- }
- if (isset($var)) {
- if ($magic_quotes_gpc) {
- if (is_array($var)) {
- foreach (array_keys($var) as $key) {
- $var[$key] = stripslashes($var[$key]);
- }
- } else {
- $var = stripslashes($var);
- }
- }
- } else {
- $var = @$default_value;
- }
- if (isset($this) && $var === null && isset($this->cgi['append'][$name])) {
- return $this->cgi['append'][$name];
- }
- return $var;
- } /* }}} */
- function get_server_var($name) /* {{{ */
- {
- if (isset($_SERVER[$name])) {
- return $_SERVER[$name];
- }
- global $HTTP_SERVER_VARS;
- if (isset($HTTP_SERVER_VARS[$name])) {
- return $HTTP_SERVER_VARS[$name];
- }
- global $$name;
- if (isset($$name)) {
- return $$name;
- }
- return null;
- } /* }}} */
- /*
- * Debug functions
- */
- function print_get_vars ($miss = 'No GET variables found') // debug only /* {{{ */
- {
- global $HTTP_GET_VARS;
- // we parse form GET variables
- if (is_array($HTTP_GET_VARS)) {
- echo "<p> Variables per GET ";
- foreach ($HTTP_GET_VARS as $k => $v) {
- if (is_array($v)) {
- foreach ($v as $akey => $aval) {
- // $HTTP_GET_VARS[$k][$akey] = strip_tags($aval);
- // $$k[$akey] = strip_tags($aval);
- echo "$k\[$akey\]=$aval ";
- }
- } else {
- // $HTTP_GET_VARS[$k] = strip_tags($val);
- // $$k = strip_tags($val);
- echo "$k=$v ";
- }
- }
- echo '</p>';
- } else {
- echo '<p>';
- echo $miss;
- echo '</p>';
- }
- } /* }}} */
- function print_post_vars($miss = 'No POST variables found') // debug only /* {{{ */
- {
- global $HTTP_POST_VARS;
- // we parse form POST variables
- if (is_array($HTTP_POST_VARS)) {
- echo "<p>Variables per POST ";
- foreach ($HTTP_POST_VARS as $k => $v) {
- if (is_array($v)) {
- foreach ($v as $akey => $aval) {
- // $HTTP_POST_VARS[$k][$akey] = strip_tags($aval);
- // $$k[$akey] = strip_tags($aval);
- echo "$k\[$akey\]=$aval ";
- }
- } else {
- // $HTTP_POST_VARS[$k] = strip_tags($val);
- // $$k = strip_tags($val);
- echo "$k=$v ";
- }
- }
- echo '</p>';
- } else {
- echo '<p>';
- echo $miss;
- echo '</p>';
- }
- } /* }}} */
- function print_vars ($miss = 'Current instance variables') // debug only /* {{{ */
- {
- echo "$miss ";
- echo 'page_name=',$this->page_name,' ';
- echo 'hn=',$this->hn,' ';
- echo 'un=',$this->un,' ';
- echo 'pw=',$this->pw,' ';
- echo 'db=',$this->db,' ';
- echo 'tb=',$this->tb,' ';
- echo 'key=',$this->key,' ';
- echo 'key_type=',$this->key_type,' ';
- echo 'inc=',$this->inc,' ';
- echo 'options=',$this->options,' ';
- echo 'fdd=',$this->fdd,' ';
- echo 'fl=',$this->fl,' ';
- echo 'fm=',$this->fm,' ';
- echo 'sfn=',htmlspecialchars($this->get_sfn_cgi_vars()),' ';
- echo 'qfn=',$this->qfn,' ';
- echo 'sw=',$this->sw,' ';
- echo 'rec=',$this->rec,' ';
- echo 'navop=',$this->navop,' ';
- echo 'saveadd=',$this->saveadd,' ';
- echo 'moreadd=',$this->moreadd,' ';
- echo 'canceladd=',$this->canceladd,' ';
- echo 'savechange=',$this->savechange,' ';
- echo 'adminchange=',$this->adminchange,' ';
- echo 'morechange=',$this->morechange,' ';
- echo 'mailchange=',$this->mailchange,' ';
- echo 'docchange=',$this->docchange,' ';
- echo 'rtfgen_detail=',$this->rtfgen_detail,' ';
- echo 'rtfgen_ticker=',$this->rtfgen_ticker,' ';
- echo 'leasing_offer=',$this->leasing_offer,' ';
- echo 'accessories=',$this->accessories,' ';
- echo 'cancelchange=',$this->cancelchange,' ';
- echo 'savedelete=',$this->savedelete,' ';
- echo 'canceldelete=',$this->canceldelete,' ';
- echo 'cancelview=',$this->cancelview,' ';
- echo 'operation=',$this->operation,' ';
- echo "\n";
- } /* }}} */
- /*
- * Display buttons at top and bottom of page
- */
- function display_list_table_buttons($total_recs, $position) /* {{{ */
- {
- #echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n";
- #echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
- #echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
- $listall = $this->inc <= 0; // Are we doing a listall?
- $disabledprev = !($this->fm > 0 && !$listall);
- $disablednext = !($this->fm + $this->inc < $total_recs && ! $listall);
- $disabledgoto = !($listall || ($disablednext && $disabledprev)) ? '' : ' disabled';
- $current_page = intval($this->fm / $this->inc) + 1;
- $total_pages = max(1, ceil($total_recs / abs($this->inc)));
- $bAdmin = $this->htmlSubmit('adminchange', 'Save', $this->getCSSclass('save', $position), false);
- ob_start();
- echo '<input class="',$this->getCSSclass('afa', $position);
- echo '" type="text" name="AfA_change">',"\n";
- $iAfa = ob_get_contents();
- ob_end_clean();
- ob_start();
- echo '<input class="',$this->getCSSclass('upenetto', $position);
- echo '" type="text" name="UPE_Netto_change">',"\n";
- $iUPENetto = ob_get_contents();
- ob_end_clean();
- ob_start();
- echo '<input class="',$this->getCSSclass('vknetto', $position);
- echo '" type="text" name="VK_Netto_change">',"\n";
- $iVKNetto = ob_get_contents();
- ob_end_clean();
- $brtfta = $this->htmlSubmit('rtfgen_ticker_all', __('Print Ticker for all'), $this->getCSSclass('rtfgen_ticker_all', $position), true);
- if (!$listall) {
- $bFirst = $this->htmlSubmit('navop', 'First', $this->getCSSclass('first', $position), false, $disabledprev);
- $bPrev = $this->htmlSubmit('navop', 'Prev', $this->getCSSclass('prev', $position), false, $disabledprev);
- }
- if ($this->add_enabled()) {
- $bAdd = $this->htmlSubmit('operation', 'Add', $this->getCSSclass('add', $position), false, false);
- }
- $bRtf = $this->htmlSubmit('rtfgen', __("Print", "Print", "GENERAL"), $this->getCSSclass('rtfgen', $position), false, false);
- $brtfd = $this->htmlSubmit('rtfgen_detail', 'Print', $this->getCSSclass('rtfgen_detail', $position), true);
- if ($this->nav_buttons()) {
- if ($this->view_enabled()) {
- $bView = $this->htmlSubmit('operation', 'View', $this->getCSSclass('view', $position), false, !$total_recs);
- }
- if ($this->change_enabled()) {
- $bChange = $this->htmlSubmit('operation', 'Change', $this->getCSSclass('change', $position), false, !$total_recs);
- }
- if ($this->copy_enabled()) {
- $bCopy = $this->htmlSubmit('operation', 'Copy', $this->getCSSclass('copy', $position), false, !$total_recs);
- }
- if ($this->delete_enabled()) {
- $bDelete= $this->htmlSubmit('operation', 'Delete', $this->getCSSclass('delete', $position), false, !$total_recs);
- }
- }
- if (!$listall) { //nav buttons are not displayed if explicit listall
- $bNext = $this->htmlSubmit('navop', 'Next', $this->getCSSclass('next', $position), false, $disablednext);
- $bLast = $this->htmlSubmit('navop', 'Last', $this->getCSSclass('last', $position), false, $disablednext);
- $bGoto = $this->htmlSubmit('navop', 'Go to', $this->getCSSclass('goto', $position), false,
- ($listall || ($disablednext && $disabledprev)));
- ob_start();
- echo '<select',$disabledgoto,' class="',$this->getCSSclass('goto', $position);
- echo '" name="',ltrim($disabledgoto),'navfm',$position,'" onChange="return this.form.submit();">',"\n";
- for ($i = 0; $i < $total_pages; $i++) {
- echo '<option',($this->fm == $this->inc * $i) ? ' selected' : '';
- echo ' value="',$this->inc * $i,'">',$i + 1,'</option>',"\n";
- }
- echo '</select>';
- $sGoto = ob_get_contents();
- ob_end_clean();
- }
- #echo '</td>',"\n";
- // Message is now written here
- if (strlen(@$this->message) > 0) {
- $tMessage = '<td class="'.$this->getCSSclass('message', $position).'">'.$this->message.'</td>'."\n";
- }
- // Display page and records statistics
- echo '<td class="',$this->getCSSclass('stats', $position),'">',"\n";
- if ($listall) {
- $current_page = 1;
- $total_pages = 1;
- }
- #echo ' ',$this->labels['Records'],': ',$total_recs;
- #echo '</td></tr></table>',"\n";
- global $smarty;
- $smarty->assign('button_first', $bFirst);
- $smarty->assign('button_prev', $bPrev);
- $smarty->assign('button_add', $bAdd);
- $smarty->assign('button_save', $bSave);
- $smarty->assign('button_admin', $bAdmin);
- $smarty->assign('button_rtfgen', $bRtf);
- $smarty->assign('button_view', $bView);
- $smarty->assign('button_change', $bChange);
- $smarty->assign('button_copy', $bCopy);
- $smarty->assign('button_delete', $bDelete);
- $smarty->assign('button_next', $bNext);
- $smarty->assign('button_last', $bLast);
- $smarty->assign('button_goto', $bGoto);
- $smarty->assign('button_rtfgen_ticker_all', $brtfta);
- // $smarty->assign('button_print',
- // '<input type=button value="'.__('Print').'" '.
- // ' onClick="location.href=\''.$_SERVER['PHP_SELF'].'?dopdf=1\';">');
- $smarty->assign('select_goto', $sGoto);
- $smarty->assign('input_afa', $iAfa);
- $smarty->assign('input_upenetto', $iUPENetto);
- $smarty->assign('input_vknetto', $iVKNetto);
- $smarty->assign('text_message', $tMessage);
- $smarty->assign('label_page', $this->labels['Page']);
- $smarty->assign('current_page', $current_page);
- $smarty->assign('label_of', $this->labels['of']);
- $smarty->assign('total_pages', $total_pages);
- $smarty->assign('label_records', $this->labels['Records']);
- $smarty->assign('total_recs', $total_recs);
- $smarty->assign('REPORT_COUNT', $total_recs);
- } /* }}} */
- /*
- * Display buttons at top and bottom of page
- */
- function display_record_buttons($position) /* {{{ */
- {
- #echo '<table class="',$this->getCSSclass('navigation', $position),'">',"\n";
- #echo '<tr class="',$this->getCSSclass('navigation', $position),'">',"\n";
- #echo '<td class="',$this->getCSSclass('buttons', $position),'">',"\n";
- $brtft = $this->htmlSubmit('rtfgen_ticker', __('Print Ticker'), $this->getCSSclass('rtfgen_ticker', $position), true);
- $LeasOff = $this->htmlSubmit('leasing_offer', __('Leasing Offer'), $this->getCSSclass('leasing_offer', $position), true);
- $Accessories = $this->htmlSubmit('accessories', __('Accessories'), $this->getCSSclass('accessories', $position), true);
- if ($this->change_operation()) {
- $bMail = $this->htmlSubmit('mailchange', __('Mail'), $this->getCSSclass('mail', $position), true);
- $bDocument = $this->htmlSubmit('docchange', __('Document'), $this->getCSSclass('document', $position), true);
- $brtfd = $this->htmlSubmit('rtfgen_detail', 'Print', $this->getCSSclass('rtfgen_detail', $position), true);
- $bSave = $this->htmlSubmit('savechange', 'Save', $this->getCSSclass('save', $position), true);
- $bApply = $this->htmlSubmit('morechange', 'Apply', $this->getCSSclass('more', $position), true);
- $bCancel = $this->htmlSubmit('cancelchange', 'Cancel', $this->getCSSclass('cancel', $position), false);
- } elseif ($this->add_operation()) {
- $bSave = $this->htmlSubmit('saveadd', 'Save', $this->getCSSclass('save', $position), true);
- $bMore = $this->htmlSubmit('moreadd', 'More', $this->getCSSclass('more', $position), true);
- $bCancel = $this->htmlSubmit('canceladd', 'Cancel', $this->getCSSclass('cancel', $position), false);
- } elseif ($this->copy_operation()) {
- $bSave = $this->htmlSubmit('saveadd', 'Save', $this->getCSSclass('save', $position), true);
- $bCancel = $this->htmlSubmit('canceladd', 'Cancel', $this->getCSSclass('cancel', $position), false);
- } elseif ($this->delete_operation()) {
- $bDelete = $this->htmlSubmit('savedelete', 'Delete', $this->getCSSclass('save', $position), true);
- $bCancel = $this->htmlSubmit('canceldelete', 'Cancel', $this->getCSSclass('cancel', $position), false);
- } elseif ($this->view_operation()) {
- if ($this->change_enabled()) {
- $bChange = $this->htmlSubmit('operation', 'Change', $this->getCSSclass('save', $position), true);
- }
- $bCancel = $this->htmlSubmit('cancelview', 'Cancel', $this->getCSSclass('cancel', $position), false);
- }
- // Message is now written here
- #echo '</td>',"\n";
- if (strlen(@$this->message) > 0) {
- $tMessage = '<td class="'.$this->getCSSclass('message', $position).'">'.$this->message.'</td>'."\n";
- }
- #echo '</tr></table>',"\n";
- global $smarty;
- $smarty->assign('button_mail', $bMail);
- $smarty->assign('button_document', $bDocument);
- $smarty->assign('button_rtfgen_detail', $brtfd);
- $smarty->assign('button_rtfgen_ticker', $brtft);
- $smarty->assign('button_leasing_offer', $LeasOff);
- $smarty->assign('button_accessories', $Accessories);
- $smarty->assign('button_save', $bSave);
- $smarty->assign('button_apply', $bApply);
- $smarty->assign('button_cancel', $bCancel);
- $smarty->assign('button_more', $bMore);
- $smarty->assign('button_delete', $bDelete);
- $smarty->assign('button_change', $bChange);
- $smarty->assign('text_message', $tMessage);
- } /* }}} */
- /*
- * Table Page Listing
- */
- function list_table() /* {{{ */
- {
- // Cancel Triggers
- if ($this->add_canceled() && isset($this->triggers['insert']['cancel'])) {
- include($this->triggers['insert']['cancel']);
- }
- if ($this->view_canceled() && isset($this->triggers['select']['cancel'])) {
- include($this->triggers['select']['cancel']);
- }
- if ($this->change_canceled() && isset($this->triggers['update']['cancel'])) {
- include($this->triggers['update']['cancel']);
- }
- if ($this->delete_canceled() && isset($this->triggers['delete']['cancel'])) {
- include($this->triggers['delete']['cancel']);
- }
- if ($this->fm == '') {
- $this->fm = 0;
- }
- if ($this->prev_operation()) {
- $this->fm = $this->fm - $this->inc;
- if ($this->fm < 0) {
- $this->fm = 0;
- }
- }
- if ($this->first_operation()) {
- $this->fm = 0;
- } // last operation must be performed below, after retrieving total_recs
- if ($this->next_operation()) {
- $this->fm += $this->inc;
- }
- if ($this->goto_operation()) {
- $this->fm = $this->navfm;
- }
- // If sort sequence has changed, restart listing
- $this->qfn != $this->prev_qfn && $this->fm = 0;
- if (0) { // DEBUG
- echo 'qfn vs. prev_qfn comparsion ';
- echo '[<b>',htmlspecialchars($this->qfn),'</b>]';
- echo '[<b>',htmlspecialchars($this->prev_qfn),'</b>]<br>';
- echo 'comparsion <u>',($this->qfn == $this->prev_qfn ? 'proved' : 'failed'),'</u>';
- echo '<hr>';
- }
- /*
- * If user is allowed to Change/Delete records, we need an extra column
- * to allow users to select a record
- */
- $select_recs = $this->key != '' &&
- ($this->change_enabled() || $this->delete_enabled() || $this->view_enabled());
- // Are we doing a listall?
- $listall = $this->inc <= 0;
- /*
- * Display the MySQL table in an HTML table
- */
- global $smarty;
- ob_start();
- $this->form_begin();
- echo $this->get_origvars_html($this->get_sfn_cgi_vars());
- echo '<input type="hidden" name="fl" value="',$this->fl,'">',"\n";
- // Display buttons at top and/or bottom of page.
- // Setup query to get num_rows. (sparky)
- $total_recs = 0;
- $count_parts = array(
- 'type' => 'select',
- 'select' => 'count(*)',
- 'from' => $this->create_join_clause(),
- 'where' => $this->make_where_from_query_opts());
- $res = $this->myquery($this->query_make($count_parts), __LINE__);
- $row = @mysql_fetch_array($res, MYSQL_NUM);
- $total_recs = $row[0];
- if ($this->last_operation()) {
- $this->fm = (int)(($total_recs-1)/$this->inc)*$this->inc;
- }
- if ($this->nav_up()) {
- $this->display_list_table_buttons($total_recs, 'up');
- #echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
- }
- if ($this->cgi['persist'] != '') {
- echo $this->get_origvars_html($this->cgi['persist']);
- }
- if (! $this->filter_operation()) {
- echo $this->get_origvars_html($this->qfn);
- }
- echo '<input type="hidden" name="qfn" value="',htmlspecialchars($this->qfn),'">',"\n";
- echo '<input type="hidden" name="fm" value="',htmlspecialchars($this->fm),'">',"\n";
- $smarty->assign('form_begin', ob_get_contents());
- ob_end_clean();
- #echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
- #echo '<tr class="',$this->getCSSclass('header'),'">',"\n";
- /*
- * System (navigation, selection) columns counting
- */
- $sys_cols = 0;
- $sys_cols += intval($this->filter_enabled() || $select_recs);
- if ($sys_cols > 0) {
- $sys_cols += intval($this->nav_buttons()
- && ($this->nav_text_links() || $this->nav_graphic_links()));
- }
- /*
- * We need an initial column(s) (sys columns)
- * if we have filters, Changes or Deletes enabled
- */
- /*
- if ($sys_cols) {
- echo '<th class="',$this->getCSSclass('header'),'" colspan="',$sys_cols,'">';
- if (false && $this->filter_enabled()) {
- if ($this->filter_operation()) {
- echo '<input class="',$this->getCSSclass('hide'),'" type="submit" name="sw" value="';
- echo $this->labels['Hide'],'">';
- echo '<input class="',$this->getCSSclass('clear'),'" type="submit" name="sw" value="';
- echo $this->labels['Clear'],'">';
- } else {
- echo '<input class="',$this->getCSSclass('search'),'" type="submit" name="sw" value="';
- echo $this->labels['Search'],'">';
- }
- } else {
- echo ' ';
- }
- echo '</th>',"\n";
- }*/
- $columnCount = 1;
- for ($k = 0; $k < $this->num_fds; $k++) {
- $fd = $this->fds[$k];
- if ($this->displayed[$k]) {
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- $css_class_name = $this->getCSSclass('header', null, null, $css_postfix);
- $fdn = $this->fdd[$fd]['name'];
- if (! $this->fdd[$fd]['sort'] || $this->password($fd)) {
- #echo '<th class="',$css_class_name,'">',$fdn,'</th>',"\n";
- } else {
- // Clicking on the current sort field reverses the sort order
- $new_sfn = $this->sfn;
- array_unshift($new_sfn, in_array("$k", $new_sfn, 1) ? "-$k" : $k);
- // echo '<th class="',$css_class_name,'">';
- $fdn = '<a class="'.$css_class_name.'" href="'
- .htmlspecialchars($this->page_name.'?fm=0&fl='.$this->fl
- .'&qfn='.rawurlencode($this->qfn).$this->qfn
- .'&'.$this->get_sfn_cgi_vars($new_sfn).$this->cgi['persist'])
- .'">'.$fdn.'</a>';
- // echo '</th>',"\n";
- }
- $smarty->assign($fd."Txt2", $fdn);
- $columnCount++;
- }
- }
- $smarty->assign('columnCount', ($columnCount));
- #echo '</tr>',"\n";
- /*
- * Prepare the SQL Query from the data definition file
- */
- $qparts['type'] = 'select';
- $qparts['select'] = $this->create_column_list();
- // Even if the key field isn't displayed, we still need its value
- if ($select_recs) {
- if (!in_array ($this->key, $this->fds)) {
- $qparts['select'] .= ','.$this->fqn($this->key);
- }
- }
- $qparts['from'] = $this->create_join_clause();
- $qparts['where'] = $this->make_where_from_query_opts();
- $handle = fopen('query2.txt',"w");
- fwrite($handle, $qparts['where']);
- fclose($handle);
- $this->filter = $qparts['where'];
- // build up the ORDER BY clause
- if (isset($this->sfn)) {
- // WTF $raw_sort_fields?
- //$raw_sort_fields = array();
- $sort_fields = array();
- $sort_fields_w = array();
- foreach ($this->sfn as $field) {
- if ($field[0] == '-') {
- $field = substr($field, 1);
- $desc = true;
- } else {
- $field = $field;
- $desc = false;
- }
- //$raw_sort_field = 'qf'.$field;
- $sort_field = $this->fqn($field);
- $sort_field_w = $this->fdd[$field]['name'];
- $this->col_has_sql($field) && $sort_field_w .= ' (sql)';
- if ($desc) {
- $sort_field .= ' DESC';
- $sort_field_w .= ' '.$this->labels['descending'];
- } else {
- $sort_field_w .= ' '.$this->labels['ascending'];
- }
- //$raw_sort_fields[] = $raw_sort_field;
- $sort_fields[] = $sort_field;
- $sort_fields_w[] = $sort_field_w;
- }
- if (count($sort_fields) > 0) {
- $sort_fields = array_reverse($sort_fields);
- $sort_fields_w = array_reverse($sort_fields_w);
- $qparts['orderby'] = join(',', $sort_fields);
- }
- }
- $to = $this->fm + $this->inc;
- if ($listall) {
- #$qparts['limit'] = $this->fm.',-1';
- } else {
- $qparts['limit'] = $this->fm.','.$this->inc;
- }
- /*
- * Main list_table() query
- *
- * Each row of the HTML table is one record from the SQL query. We must
- * perform this query before filter printing, because we want to use
- * mysql_field_len() function. We will also fetch the first row to get
- * the field names.
- */
- $query = $this->query_make($qparts);
- $res = $this->myquery($query, __LINE__);
- if ($res == false) {
- $this->error('invalid SQL query', $query);
- return false;
- }
- $row = @mysql_fetch_array($res, MYSQL_ASSOC);
- /* FILTER {{{
- *
- * Draw the filter and fill it with any data typed in last pass and stored
- * in the array parameter keyword 'filter'. Prepare the SQL WHERE clause.
- */
- if ($this->filter_operation()) {
- // Filter row retrieval
- $fields = false;
- $filter_row = $row;
- if (! is_array($filter_row)) {
- unset($qparts['where']);
- $query = $this->query_make($qparts);
- $res = $this->myquery($query, __LINE__);
- if ($res == false) {
- $this->error('invalid SQL query', $query);
- return false;
- }
- $filter_row = @mysql_fetch_array($res, MYSQL_ASSOC);
- }
- /* Variable $fields is used to get index of particular field in
- result. That index can be passed in example to mysql_field_len()
- function. Use field names as indexes to $fields array. */
- if (is_array($filter_row)) {
- $fields = array_flip(array_keys($filter_row));
- }
- /*
- if ($fields != false) {
- $css_class_name = $this->getCSSclass('filter');
- echo '<tr class="',$css_class_name,'">',"\n";
- echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">';
- echo '<input class="',$this->getCSSclass('query'),'" type="submit" name="filter" value="';
- echo $this->labels['Query'],'"></td>',"\n";
- for ($k = 0; $k < $this->num_fds; $k++) {
- if (! $this->displayed[$k]) {
- continue;
- }
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- $css_class_name = $this->getCSSclass('filter', null, null, $css_postfix);
- $this->field_name = $this->fds[$k];
- $fd = $this->field_name;
- $this->field = $this->fdd[$fd];
- $l = 'qf'.$k;
- $lc = 'qf'.$k.'_comp';
- $li = 'qf'.$k.'_id';
- if ($this->clear_operation()) {
- $m = null;
- $mc = null;
- $mi = null;
- } else {
- $m = $this->get_cgi_var($l);
- $mc = $this->get_cgi_var($lc);
- $mi = $this->get_cgi_var($li);
- }
- echo '<td class="',$css_class_name,'">';
- if ($this->password($k)) {
- echo ' ';
- } else if ($this->fdd[$fd]['select'] == 'D' || $this->fdd[$fd]['select'] == 'M') {
- // Multiple fields processing
- // Default size is 2 and array required for values.
- $from_table = ! $this->col_has_values($k) || isset($this->fdd[$k]['values']['table']);
- $vals = $this->set_values($k, array('*' => '*'), null, $from_table);
- $selected = $mi;
- $multiple = $this->col_has_multiple_select($k);
- $multiple |= $this->fdd[$fd]['select'] == 'M';
- $readonly = false;
- $strip_tags = true;
- $escape = true;
- echo $this->htmlSelect($l.'_id', $css_class_name, $vals,
- $selected, $multiple, $readonly, $strip_tags, $escape);
- } elseif ($this->fdd[$fd]['select'] == 'N' || $this->fdd[$fd]['select'] == 'T') {
- $size_ml_props = '';
- $maxlen = intval($this->fdd[$k]['maxlen']);
- $maxlen > 0 || $maxlen = intval(@mysql_field_len($res, $fields["qf$k"]));
- $size = isset($this->fdd[$k]['size']) ? $this->fdd[$k]['size']
- : ($maxlen < 30 ? min($maxlen, 8) : 12);
- $size && $size_ml_props .= ' size="'.$size.'"';
- $maxlen && $size_ml_props .= ' maxlength="'.$maxlen.'"';
- if ($this->fdd[$fd]['select'] == 'N') {
- $mc = in_array($mc, $this->comp_ops) ? $mc : '=';
- echo $this->htmlSelect($l.'_comp', $css_class_name, $this->comp_ops, $mc);
- }
- echo '<input class="',$css_class_name,'" value="';
- echo htmlspecialchars(@$m),'" type="text" name="qf',$k,'"',$size_ml_props;
- echo ' onKeyPress="return phpMyEdit_filter_handler(this.form, event);">';
- } else {
- echo ' ';
- }
- echo '</td>',"\n";
- }
- echo '</tr>',"\n";
- }
- */
- } // }}}
- /*
- * Display sorting sequence
- */
- global $smarty;
- ob_start();
- if ($qparts['orderby'] && $this->display['sort']) {
- $css_class_name = $this->getCSSclass('sortinfo');
- #echo '<tr class="',$css_class_name,'">',"\n";
- #echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">';
- echo '<a class="',$css_class_name,'" href="';
- echo htmlspecialchars($this->get_server_var('PHP_SELF').'?fl='.$this->fl.'&fm='.$this->fm
- .'&qfn='.rawurlencode($this->qfn).$this->qfn.$this->cgi['persist']);
- echo '">',$this->labels['Clear'],'</a>'; //</td>',"\n";
- echo ' » ';
- #echo '<td class="',$css_class_name,'" colspan="',$this->num_fields_displayed,'">';
- echo $this->labels['Sorted By'],': ',join(', ', $sort_fields_w); //,'</td></tr>',"\n";
- }
- $smarty->assign('sortInfo', ob_get_contents());
- ob_end_clean();
- /*
- * Display the current query
- */
- $text_query = $this->make_where_from_query_opts(null, true);
- /*if ($text_query != '' && $this->display['query']) {
- $css_class_name = $this->getCSSclass('queryinfo');
- echo '<tr class="',$css_class_name,'">',"\n";
- echo '<td class="',$css_class_name,'" colspan="',$sys_cols,'">';
- echo '<a class="',$css_class_name,'" href="';
- echo htmlspecialchars($this->get_server_var('PHP_SELF').'?fl='.$this->fl.'&fm='.$this->fm
- .'&qfn='.rawurlencode($this->qfn).'&'.$this->get_sfn_cgi_vars().$this->cgi['persist']);
- echo '">',$this->labels['Clear'],'</a></td>',"\n";
- echo '<td class="',$css_class_name,'" colspan="',$this->num_fields_displayed,'">';
- echo $this->labels['Current Query'],': ',htmlspecialchars($text_query),'</td></tr>',"\n";
- }
- */
- if ($this->nav_text_links() || $this->nav_graphic_links()) {
- $qstrparts = array();
- strlen($this->fl) > 0 && $qstrparts[] = 'fl='.$this->fl;
- strlen($this->fm) > 0 && $qstrparts[] = 'fm='.$this->fm;
- count($this->sfn) > 0 && $qstrparts[] = $this->get_sfn_cgi_vars();
- strlen($this->cgi['persist']) > 0 && $qstrparts[] = $this->cgi['persist'];
- $qpview = $qstrparts;
- $qpcopy = $qstrparts;
- $qpchange = $qstrparts;
- $qpdelete = $qstrparts;
- $qpview[] = 'operation='.$this->labels['View'];
- $qpcopy[] = 'operation='.$this->labels['Copy'];
- $qpchange[] = 'operation='.urlencode($this->labels['Change']);
- $qpdelete[] = 'operation='.urlencode($this->labels['Delete']);
- $qpviewStr = '?'.join('&',$qpview).$this->qfn;
- $qpcopyStr = '?'.join('&',$qpcopy).$this->qfn;
- $qpchangeStr = '?'.join('&',$qpchange).$this->qfn;
- $qpdeleteStr = '?'.join('&',$qpdelete).$this->qfn;
- }
- $smarty->assign_by_ref('res', $res);
- ob_start();
- $this->form_end();
- $smarty->assign('form_end', ob_get_contents());
- ob_end_clean();
- }
- function move_first() {
- global $smarty;
- $res = $smarty->get_template_vars('res');
- @mysql_data_seek($res, 0);
- }
- function fetch_row() {
- global $smarty;
- $res = $smarty->get_template_vars('res');
- $qpchange[] = 'operation='.urlencode($this->labels['Change'])."&fm=".$this->fm;
- $qpcopy[] = 'operation='.$this->labels['Copy']."&fm=".$this->fm;
- $qpdelete[] = 'operation='.urlencode($this->labels['Delete'])."&fm=".$this->fm;
- $qpchangeStr = '?'.join('&',$qpchange).$this->qfn;
- $qpcopyStr = '?'.join('&',$qpcopy).$this->qfn;
- $qpdeleteStr = '?'.join('&',$qpdelete).$this->qfn;
- $res2 = mysql_connect('localhost', 'qbuilder', 'qbuilder');
- mysql_select_db('qbuilder', $res2);
- $row = @mysql_fetch_array($res, MYSQL_ASSOC);
- if ($row == false) return false;
- $key_rec = urlencode($row['qf'.$this->key_num]);
- $qchangeStr = $qpchangeStr . '&rec='.$key_rec;
- $qcopyStr = $qpcopyStr . '&rec='.$key_rec;
- $qdeleteStr = $qpdeleteStr . '&rec='.$key_rec;
- //$smarty->assign('selectedrec', $this->rec); // Hier wird der zuletzt selektierte key gespeichert
- //$smarty->assign('repid', $_SESSION['repid']);
- //$smarty->assign('reptb', $_SESSION['reptb']);
- $query2 = 'SELECT pkey FROM qb_report WHERE id=' . $_SESSION['repid'] . ';';
- $result2 = mysql_query($query2);
- $row2 = mysql_fetch_object($result2);
- // mysql_select_db("qbuilder") or die ("DB existiert net.");
- //echo 'SELECT ' . $row2->pkey . ' FROM ' . $_SESSION['reptb'] . ' WHERE qb_id = "' . $this->rec . '";';
- $query3 = 'SELECT ' . $row2->pkey . ' FROM ' . $_SESSION['reptb'] . ' WHERE qb_id = "' . $this->rec . '";';
- $result3 = mysql_query($query3);
- $row3 = @mysql_fetch_object($result3);//$result3);
- $identifier = '';
- //$smarty->assign('selectedrec', $row2->pkey);
- foreach ( explode(',', $row2->pkey) as $pkey ) {
- if ( strlen($row3->$pkey) != 0 ) {
- $identifier .= $row3->$pkey;
- }
- }
- $smarty->assign('thisrec', $identifier);
- $css_class_name = $this->getCSSclass('navigation', null, true);
- if ($this->nav_graphic_links()) {
- $printed_out = false;
- if ($this->change_enabled()) {
- ob_start();
- $printed_out && print(' ');
- $printed_out = true;
- echo '<a class="',$css_class_name,'" href="';
- echo htmlspecialchars($this->page_name.$qchangeStr),'"><img class="';
- echo $css_class_name,'" src="',$this->url['images'];
- echo 'pme-change.png" height="15" width="16" border="0" alt="';
- echo htmlspecialchars($this->labels['Change']),'" title="';
- echo htmlspecialchars($this->labels['Change']),'"></a>';
- $xrow['link_change'] = ob_get_contents();
- ob_end_clean();
- }
- if ($this->copy_enabled()) {
- ob_start();
- $printed_out && print(' ');
- $printed_out = true;
- echo ' <a class="',$css_class_name,'" href="';
- echo htmlspecialchars($this->page_name.$qcopyStr),'"><img class="';
- echo $css_class_name,'" src="',$this->url['images'];
- echo 'pme-copy.png" height="15" width="16" border="0" alt="';
- echo htmlspecialchars($this->labels['Copy']),'" title="';
- echo htmlspecialchars($this->labels['Copy']),'"></a>';
- $xrow['link_copy'] = ob_get_contents();
- ob_end_clean();
- }
- if ($this->delete_enabled($key_rec)) {
- ob_start();
- $printed_out && print(' ');
- $printed_out = true;
- echo '<a class="',$css_class_name,'" href="';
- echo htmlspecialchars($this->page_name.$qdeleteStr),'"><img class="';
- echo $css_class_name,'" src="',$this->url['images'];
- echo 'pme-delete.png" height="15" width="16" border="0" alt="';
- echo htmlspecialchars($this->labels['Delete']),'" title="';
- echo htmlspecialchars($this->labels['Delete']),'"></a>';
- $xrow['link_delete'] = ob_get_contents();
- ob_end_clean();
- }
- } /* }}} */
- for ($k = 0; $k < $this->num_fds; $k++) { /* {{{ */
- $fd = $this->fds[$k];
- if (! $this->displayed[$k]) {
- continue;
- }
- $css_postfix = @$this->fdd[$k]['css']['postfix'];
- $css_class_name = $this->getCSSclass('cell', null, true, $css_postfix);
- if ($this->password($k)) {
- $xrow[$fd] = $this->labels['hidden'];
- continue;
- }
- $xrow[$fd] = $this->cellDisplay($k, $row, $css_class_name);
- } /* }}} */
- return $xrow;
- }
- function assign_rows() {
- global $smarty;
- $rows_count = intval($smarty->get_template_vars('rows_count'));
- if ($rows_count > 0) {
- /*$tpl_vars = $smarty->get_template_vars();
- print_r($tpl_vars);*/
- $rows = $smarty->get_template_vars('rows_next');
- $smarty->assign_by_ref('rows', $rows);
- } else {
- $this->move_first();
- $rows = $this->fetch_row();
- $smarty->assign_by_ref('rows', $rows);
- }
- $smarty->assign_by_ref('rows_next', $this->fetch_row());
- if ($rows) {
- $rows_count++;
- $smarty->assign('rows_count', $rows_count);
- }
- return $rows;
- }
- function display_record() /* {{{ */
- {
- // PRE Triggers
- $ret = true;
- if (($this->change_operation() || $this->change_operation()) && isset($this->triggers['update']['pre'])) {
- $ret = include($this->triggers['update']['pre']);
- // if PRE update fails, then back to view operation
- if (! $ret) {
- $this->operation = $this->labels['View'];
- $ret = true;
- }
- }
- if (($this->add_operation() || $this->copy_operation())
- && isset($this->triggers['insert']['pre'])) {
- $ret = include($this->triggers['insert']['pre']);
- }
- if ($this->view_operation() && isset($this->triggers['select']['pre'])) {
- $ret = include($this->triggers['select']['pre']);
- }
- if ($this->delete_operation() && isset($this->triggers['delete']['pre'])) {
- $ret = include($this->triggers['delete']['pre']);
- }
- // if PRE insert/view/delete fail, then back to the list
- if ($ret == false) {
- $this->operation = '';
- $this->list_table();
- return;
- }
- global $smarty;
- ob_start();
- $this->form_begin();
- if ($this->cgi['persist'] != '') {
- echo $this->get_origvars_html($this->cgi['persist']);
- }
- echo $this->get_origvars_html($this->get_sfn_cgi_vars());
- echo $this->get_origvars_html($this->qfn);
- echo '<input type="hidden" name="qfn" value="',htmlspecialchars($this->qfn),'">',"\n";
- echo '<input type="hidden" name="rec" value="',($this->copy_operation()?'':$this->rec),'">',"\n";
- echo '<input type="hidden" name="fm" value="',$this->fm,'">',"\n";
- echo '<input type="hidden" name="fl" value="',$this->fl,'">',"\n";
- $smarty->assign('form_begin', ob_get_contents());
- ob_end_clean();
- if ($this->nav_up()) {
- $this->display_record_buttons('up');
- #echo '<hr class="',$this->getCSSclass('hr', 'up'),'">',"\n";
- if ($this->tabs_enabled()) {
- $this->display_tab_labels('up');
- }
- }
- if ($this->tabs_enabled()) {
- #echo '<div id="phpMyEdit_tab0">',"\n";
- }
- #echo '<table class="',$this->getCSSclass('main'),'" summary="',$this->tb,'">',"\n";
- if ($this->add_operation()) {
- $this->display_add_record();
- } else {
- $this->display_copy_change_delete_record();
- }
- #echo '</table>',"\n";
- #echo '</div>',"\n";
- if ($this->nav_down()) {
- /*
- if ($this->tabs_enabled()) {
- $this->display_tab_labels('down');
- }
- echo '<hr class="',$this->getCSSclass('hr', 'down'),'">',"\n";
- $this->display_record_buttons('down');
- */
- }
- ob_start();
- $this->form_end();
- $smarty->assign('form_end', ob_get_contents());
- ob_end_clean();
- } /* }}} */
- /*
- * Action functions
- */
- function do_add_record() /* {{{ */
- {
- // Preparing query
- $query = '';
- $key_col_val = '';
- for ($k = 0; $k < $this->num_fds; $k++) {
- if ($this->processed($k)) {
- }
- }
- $vals_quoted = array();
- $newvals = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
- if ($this->processed($k)) {
- $fd = $this->fds[$k];
- if ($this->readonly($k)) {
- $fn = (string) @$this->fdd[$k]['default'];
- } else {
- $fn = $this->get_cgi_var($this->fds[$k]);
- }
- if ($fd == $this->key) {
- $key_col_val = $fn;
- }
- if ($query == '') {
- $query = 'INSERT INTO '.$this->tb.' ('.$fd; // )
- } else {
- $query .= ','.$fd;
- }
- $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
- if ($this->col_has_sqlw($k)) {
- $val = $newvals[$this->fds[$k]];
- $val_as = addslashes($val);
- $val_qas = '"'.addslashes($val).'"';
- $vals_quoted[$k] = $this->substituteVars(
- $this->fdd[$k]['sqlw'], array(
- 'val_qas' => $val_qas,
- 'val_as' => $val_as,
- 'val' => $val
- ));
- } else {
- $vals_quoted[$k] = addslashes($newvals[$this->fds[$k]]);
- $vals_quoted[$k] = "'".$vals_quoted[$k]."'";
- }
- }
- }
- // Creating array of changed keys ($changed)
- $changed = array_keys($newvals);
- // Before trigger
- if (isset($this->triggers['insert']['before'])) {
- $ret = include($this->triggers['insert']['before']);
- if ($ret == false) {
- return false;
- }
- }
- // Real query (no additional query in this method)
- $query .= ') VALUES ('.join(',',$vals_quoted).')'; // )
- $res = $this->myquery($query, __LINE__);
- $this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record added'];
- if (! $res) {
- return false;
- }
- // Notify list
- if (@$this->notify['insert'] || @$this->notify['all']) {
- $this->email_notify(false, $newvals);
- }
- // Note change in log table
- if ($this->logtable) {
- $query = sprintf('INSERT INTO %s'
- .' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
- .' VALUES (NOW(), "%s", "%s", "insert", "%s", "%s", "", "", "%s")',
- $this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
- addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
- addslashes($key_col_val), addslashes(serialize($newvals)));
- $this->myquery($query, __LINE__);
- }
- // After trigger
- if (isset($this->triggers['insert']['after'])) {
- $ret = include($this->triggers['insert']['after']);
- if ($ret == false) {
- return false;
- }
- }
- return true;
- } /* }}} */
- function do_change_record() /* {{{ */
- {
- // Preparing queries
- $query_real = '';
- $query_oldrec = '';
- $newvals = array();
- $oldvals = array();
- $changed = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
- $fd = $this->fds[$k];
- $fn = $this->get_cgi_var($fd);
- $multiple = is_array($fn) ? false : true;
- if(!$multiple){
- $ids = array_keys($fn);
- break;
- }
- }
- if($multiple){
- //old save function (if only one record is edited)
- for ($k = 0; $k < $this->num_fds; $k++) {
- if ($this->processed($k) && !$this->readonly($k)) {
- $fd = $this->fds[$k];
- $fn = $this->get_cgi_var($fd);
- $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
- if ($this->col_has_sqlw($k)) {
- $val = $newvals[$this->fds[$k]];
- $val_as = addslashes($val);
- $val_qas = '"'.addslashes($val).'"';
- $newValue = $this->substituteVars(
- $this->fdd[$k]['sqlw'], array(
- 'val_qas' => $val_qas,
- 'val_as' => $val_as,
- 'val' => $val
- ));
- } else {
- $newValue = $newvals[$this->fds[$k]];
- $newValue = "'".addslashes($newValue)."'";
- }
- if ($query_real == '') {
- $query_real = 'UPDATE '.$this->tb.' SET '.$fd.'='.$newValue;
- $query_oldrec = 'SELECT '.$fd;
- } else {
- $query_real .= ','.$fd.'='.$newValue;
- $query_oldrec .= ','.$fd;
- }
- }
- }
- $where_part = " WHERE (".$this->key.'='.$this->key_delim.$this->rec.$this->key_delim.')';
- if ($query_real) $query_real .= $where_part;
- if ($query_oldrec == '') $query_oldrec = 'SELECT * ';
- $query_oldrec .= ' FROM ' . $this->tb . $where_part;
- // Additional query (must go before real query)
- $res = $this->myquery($query_oldrec, __LINE__);
- $oldvals = @mysql_fetch_array($res, MYSQL_ASSOC);
- @mysql_free_result($res);
- // Creating array of changed keys ($changed)
- for ($k = 0; $k < $this->num_fds; $k++) {
- $key = $this->fds[$k];
- if (! $this->processed($k) || $this->readonly($k) || $oldvals[$key] == $newvals[$key]) {
- continue;
- }
- $changed[] = $key;
- }
- // Before trigger
- if (isset($this->triggers['update']['before'])) {
- $ret = include($this->triggers['update']['before']);
- if ($ret == false) {
- return false;
- }
- }
- // Real query
- if ($query_real) {
- $res = $this->myquery($query_real, __LINE__);
- $this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record changed'];
- if (! $res) {
- return false;
- }
- }
- // Another additional query (must go after real query)
- $res = $this->myquery($query_oldrec, __LINE__);
- $newvals = @mysql_fetch_array($res, MYSQL_ASSOC);
- @mysql_free_result($res);
- // Creating array of changed keys ($changed)
- $changed = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
- $key = $this->fds[$k];
- if (! $this->processed($k) || $this->readonly($k) || $oldvals[$key] == $newvals[$key]) {
- continue;
- }
- $changed[] = $key;
- }
- // Notify list
- if (@$this->notify['update'] || @$this->notify['all']) {
- if (count($changed) > 0) {
- $this->email_notify($oldvals, $newvals);
- }
- }
- // Note change in log table
- if ($this->logtable) {
- foreach ($changed as $key) {
- $qry = sprintf('INSERT INTO %s'
- .' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
- .' VALUES (NOW(), "%s", "%s", "update", "%s", "%s", "%s", "%s", "%s")',
- $this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
- addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
- addslashes($this->rec), addslashes($key),
- addslashes($oldvals[$key]), addslashes($newvals[$key]));
- $this->myquery($qry, __LINE__);
- }
- }
- // After trigger
- if (isset($this->triggers['update']['after'])) {
- $ret = include($this->triggers['update']['after']);
- if ($ret == false) {
- return false;
- }
- }
- }
- else
- {
- //new save function (if more records are edited)
- foreach ($ids as $key => $id){
- $this -> rec = $id;
- for ($k = 0; $k < $this->num_fds; $k++) {
- if ($this->processed($k) && !$this->readonly($k)) {
- $fd = $this->fds[$k];
- $fn = $this->get_cgi_var($fd);
- if ( $fn == '' && $fd != 'Fgst') continue;
- if ( $fd == 'Fgst' ) { $unique=$fn[$id]; continue; }
- $fn = $fn[$id];
- $newvals[$this->fds[$k]] = $fn;
- if ($this->col_has_sqlw($k)) {
- $val = $newvals[$this->fds[$k]];
- $val_as = addslashes($val);
- $val_qas = '"'.addslashes($val).'"';
- $newValue = $this->substituteVars(
- $this->fdd[$k]['sqlw'], array(
- 'val_qas' => $val_qas,
- 'val_as' => $val_as,
- 'val' => $val
- ));
- } else {
- $newValue = $newvals[$this->fds[$k]];
- $newValue = "'".addslashes($newValue)."'";
- }
- if ($query_real == '') {
- $query_real = 'UPDATE '.$this->tb.' SET '.$fd.'='.$newValue;
- $query_oldrec = 'SELECT '.$fd;
- } else {
- $query_real .= ','.$fd.'='.$newValue;
- $query_oldrec .= ','.$fd;
- }
- }
- }
- $filter = file_get_contents('query2.txt');
- //$where_part = (($filter!=''||strpos($filter, "'"))?" WHERE " . substr($filter, 0, strlen($filter)-1) . ' AND Fgst="'.$this->key_delim.$unique.$this->key_delim.'")':" WHERE (" . $this->key.'="'.$this->key_delim.$this->rec.$this->key_delim.'")');
- $where_part = (($filter!=''||strpos($filter, "'"))?' WHERE ' . substr($filter, 0, strlen($filter)-1) . ')':' WHERE (' . $this->key.'="'.$this->key_delim.$this->rec.$this->key_delim.'")');
- $where_part = (($filter!=''||strpos($filter, "'"))?preg_replace('/\'\%\'/', '\''.$this->key_delim.$unique.$this->key_delim.'\'', $where_part):' WHERE (' . $this->key.'="'.$this->key_delim.$this->rec.$this->key_delim.'")');
- if ($query_real) $query_real .= $where_part;
- if ($query_oldrec == '') $query_oldrec = 'SELECT * ';
- $query_oldrec .= ' FROM ' . $this->tb . $where_part;
- // Additional query (must go before real query)
- $res = $this->myquery($query_oldrec, __LINE__);
- $oldvals = @mysql_fetch_array($res, MYSQL_ASSOC);
- @mysql_free_result($res);
- // Creating array of changed keys ($changed)
- for ($k = 0; $k < $this->num_fds; $k++) {
- $key = $this->fds[$k];
- if (! $this->processed($k) || $this->readonly($k) || $oldvals[$key] == $newvals[$key]) {
- continue;
- }
- $changed[] = $key;
- }
- // Before trigger
- if (isset($this->triggers['update']['before'])) {
- $ret = include($this->triggers['update']['before']);
- if ($ret == false) {
- return false;
- }
- }
- //file_put_contents('query.txt', $query_real);
- $handle = fopen('query.txt', 'w');
- fwrite($handle, $query_real);
- fclose($handle);
- // Real query
- if ($query_real) {
- $res = $this->myquery($query_real, __LINE__);
- $this->message += @mysql_affected_rows($this->dbh);
- if (! $res) {
- return false;
- }
- }
- // Another additional query (must go after real query)
- $res = $this->myquery($query_oldrec, __LINE__);
- $newvals = @mysql_fetch_array($res, MYSQL_ASSOC);
- @mysql_free_result($res);
- // Creating array of changed keys ($changed)
- $changed = array();
- for ($k = 0; $k < $this->num_fds; $k++) {
- $key = $this->fds[$k];
- if (! $this->processed($k) || $this->readonly($k) || $oldvals[$key] == $newvals[$key]) {
- continue;
- }
- $changed[] = $key;
- }
- // Notify list
- if (@$this->notify['update'] || @$this->notify['all']) {
- if (count($changed) > 0) {
- $this->email_notify($oldvals, $newvals);
- }
- }
- // Note change in log table
- if ($this->logtable) {
- foreach ($changed as $key) {
- $qry = sprintf('INSERT INTO %s'
- .' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
- .' VALUES (NOW(), "%s", "%s", "update", "%s", "%s", "%s", "%s", "%s")',
- $this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
- addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
- addslashes($this -> rec), addslashes($key),
- addslashes($oldvals[$key]), addslashes($newvals[$key]));
- $this->myquery($qry, __LINE__);
- }
- }
- // After trigger
- if (isset($this->triggers['update']['after'])) {
- $ret = include($this->triggers['update']['after']);
- if ($ret == false) {
- return false;
- }
- }
- unset($fd, $fn, $newvals, $query_oldrec, $query_real);
- }
- $this->message .= ' '.$this->labels['record changed'];
- }
- return true;
- } /* }}} */
- function do_delete_record() /* {{{ */
- {
- // Additional query
- $query = 'SELECT * FROM '.$this->tb.' WHERE ('.$this->key.' = '
- .$this->key_delim.$this->rec.$this->key_delim.')'; // )
- $res = $this->myquery($query, __LINE__);
- $oldvals = @mysql_fetch_array($res, MYSQL_ASSOC);
- @mysql_free_result($res);
- // Creating array of changed keys ($changed)
- if (!is_array($oldvals)) $oldvals = array();
- $changed = array_keys($oldvals);
- // Before trigger
- if (isset($this->triggers['delete']['before'])) {
- $ret = include($this->triggers['delete']['before']);
- if ($ret == false) {
- return false;
- }
- }
- // Real query
- $query = 'DELETE FROM '.$this->tb.' WHERE ('.$this->key.' = '
- .$this->key_delim.$this->rec.$this->key_delim.')'; // )
- $res = $this->myquery($query, __LINE__);
- $this->message = @mysql_affected_rows($this->dbh).' '.$this->labels['record deleted'];
- if (! $res) {
- return false;
- }
- // Notify list
- if (@$this->notify['delete'] || @$this->notify['all']) {
- $this->email_notify($oldvals, false);
- }
- // Note change in log table
- if ($this->logtable) {
- $query = sprintf('INSERT INTO %s'
- .' (updated, user, host, operation, tab, rowkey, col, oldval, newval)'
- .' VALUES (NOW(), "%s", "%s", "delete", "%s", "%s", "%s", "%s", "")',
- $this->logtable, addslashes($this->get_server_var('REMOTE_USER')),
- addslashes($this->get_server_var('REMOTE_ADDR')), addslashes($this->tb),
- addslashes($this->rec), addslashes($key), addslashes(serialize($oldvals)));
- $this->myquery($query, __LINE__);
- }
- // After trigger
- if (isset($this->triggers['delete']['after'])) {
- $ret = include($this->triggers['delete']['after']);
- if ($ret == false) {
- return false;
- }
- }
- return true;
- } /* }}} */
- function email_notify($old_vals, $new_vals) /* {{{ */
- {
- if (! function_exists('mail')) {
- return false;
- }
- if ($old_vals != false && $new_vals != false) {
- $action = 'update';
- $subject = 'Record updated in';
- $body = 'An item with '.$this->fdd[$this->key]['name'].' = '
- .$this->key_delim.$this->rec.$this->key_delim .' was updated in';
- $vals = $new_vals;
- } elseif ($new_vals != false) {
- $action = 'insert';
- $subject = 'Record added to';
- $body = 'A new item was added into';
- $vals = $new_vals;
- } elseif ($old_vals != false) {
- $action = 'delete';
- $subject = 'Record deleted from';
- $body = 'An item was deleted from';
- $vals = $old_vals;
- } else {
- return false;
- }
- $addr = $this->get_server_var('REMOTE_ADDR');
- $user = $this->get_server_var('REMOTE_USER');
- $body = 'This notification e-mail was automatically generated by phpMyEdit.'."\n\n".$body;
- $body .= ' table '.$this->tb.' in MySQL database '.$this->db.' on '.$this->page_name;
- $body .= ' by '.($user == '' ? 'unknown user' : "user $user").' from '.$addr;
- $body .= ' at '.date('d/M/Y H:i').' with the following fields:'."\n\n";
- $i = 1;
- foreach ($vals as $k => $text) {
- $name = isset($this->fdd[$k]['name~'])
- ? $this->fdd[$k]['name~'] : $this->fdd[$k]['name'];
- if ($action == 'update') {
- if ($old_vals[$k] == $new_vals[$k]) {
- continue;
- }
- $body .= sprintf("[%02s] %s (%s)\n WAS: %s\n IS: %s\n",
- $i, $name, $k, $old_vals[$k], $new_vals[$k]);
- } else {
- $body .= sprintf('[%02s] %s (%s): %s'."\n", $i, $name, $k, $text);
- }
- $i++;
- }
- $body .= "\n--\r\n"; // \r is needed for signature separating
- $body .= "phpMyEdit\ninstant MySQL table editor and code generator\n";
- $body .= "http://www.platon.sk/projects/phpMyEdit/\n\n";
- $subject = @$this->notify['prefix'].$subject.' '.$this->db.'.'.$this->tb;
- $subject = trim($subject); // just for sure
- $wrap_w = intval(@$this->notify['wrap']);
- $wrap_w > 0 || $wrap_w = 72;
- $from = (string) @$this->notify['from'];
- $from != '' || $from = 'webmaster@'.strtolower($this->get_server_var('SERVER_NAME'));
- $headers = 'From: '.$from."\n".'X-Mailer: PHP/'.phpversion().' (phpMyEdit)';
- $body = wordwrap($body, $wrap_w, "\n", 1);
- $emails = (array) $this->notify[$action] + (array) $this->notify['all'];
- foreach ($emails as $email) {
- if (! empty($email)) {
- mail(trim($email), $subject, $body, $headers);
- }
- }
- return true;
- } /* }}} */
- /*
- * Recreate functions
- */
- function recreate_fdd() /* {{{ */
- {
- // TODO: one level deeper browsing
- $this->page_type = 'L'; // list by default
- $this->filter_operation() && $this->page_type = 'F';
- $this->view_operation() && $this->page_type = 'V';
- $this->delete_operation() && $this->page_type = 'D';
- $this->add_operation() && $this->page_type = 'A';
- $this->change_operation() && $this->page_type = 'C';
- $this->copy_operation() && $this->page_type = 'P';
- // Restore backups (if exists)
- foreach (array_keys($this->fdd) as $column) {
- foreach (array_keys($this->fdd[$column]) as $col_option) {
- if ($col_option[strlen($col_option) - 1] != '~')
- continue;
- $this->fdd[$column][substr($col_option, 0, strlen($col_option) - 1)]
- = $this->fdd[$column][$col_option];
- unset($this->fdd[$column][$col_option]);
- }
- }
- foreach (array_keys($this->fdd) as $column) {
- foreach (array_keys($this->fdd[$column]) as $col_option) {
- if (! strchr($col_option, '|')) {
- continue;
- }
- $col_ar = explode('|', $col_option, 2);
- if (! stristr($col_ar[1], $this->page_type)) {
- continue;
- }
- // Make field backups
- $this->fdd[$column][$col_ar[0] .'~'] = $this->fdd[$column][$col_ar[0]];
- $this->fdd[$column][$col_option.'~'] = $this->fdd[$column][$col_option];
- // Set particular field
- $this->fdd[$column][$col_ar[0]] = $this->fdd[$column][$col_option];
- unset($this->fdd[$column][$col_option]);
- }
- }
- } /* }}} */
- function recreate_displayed() /* {{{ */
- {
- $field_num = 0;
- $num_fields_displayed = 0;
- $this->fds = array();
- $this->displayed = array();
- $this->guidance = false;
- foreach (array_keys($this->fdd) as $key) {
- if (preg_match('/^\d*$/', $key)) { // skipping numeric keys
- continue;
- }
- $this->fds[$field_num] = $key;
- /* We must use here displayed() function, because displayed[] array
- is not created yet. We will simultaneously create that array as well. */
- if ($this->displayed[$field_num] = $this->displayed($field_num)) {
- $num_fields_displayed++;
- }
- if (is_array(@$this->fdd[$key]['values']) && ! isset($this->fdd[$key]['values']['table'])) {
- foreach ($this->fdd[$key]['values'] as $val) {
- $this->fdd[$key]['values2'][$val] = $val;
- }
- unset($this->fdd[$key]['values']);
- }
- isset($this->fdd[$key]['help']) && $this->guidance = true;
- $this->fdd[$field_num] = $this->fdd[$key];
- $field_num++;
- }
- $this->num_fds = $field_num;
- $this->num_fields_displayed = $num_fields_displayed;
- $this->key_num = array_search($this->key, $this->fds);
- /* Adds first displayed column into sorting fields by replacing last
- array entry. Also remove duplicite values and change column names to
- their particular field numbers.
- Note that entries like [0]=>'9' [1]=>'-9' are correct and they will
- have desirable sorting behaviour. So there is no need to remove them.
- */
- for ($k = 0; ! $this->displayed[$k]; $k++);
- #if (count($this->sfn)>0) $this->sfn[count($this->sfn) - 1] = "$k"; // important quotes
- if (!is_array($this->sfn)) $this->sfn = array();
- $this->sfn = array_unique($this->sfn);
- $check_ar = array();
- foreach ($this->sfn as $key => $val) {
- if (preg_match('/^[-]?\d*$/', $val)) { // skipping numeric keys
- $val = abs($val);
- if (in_array($val, $check_ar) || $this->password($val)) {
- unset($this->sfn[$key]);
- } else {
- $check_ar[] = $val;
- }
- continue;
- }
- if ($val[0] == '-') {
- $val = substr($val, 1);
- $minus = '-';
- } else {
- $minus = '';
- }
- if (($val = array_search($val, $this->fds)) === false || $this->password($val)) {
- unset($this->sfn[$key]);
- } else {
- $val = intval($val);
- if (in_array($val, $check_ar)) {
- unset($this->sfn[$key]);
- } else {
- $this->sfn[$key] = $minus.$val;
- $check_ar[] = $val;
- }
- }
- }
- $this->sfn = array_unique($this->sfn);
- return true;
- } /* }}} */
- /*
- * Error handling function
- */
- function error($message, $additional_info = '') /* {{{ */
- {
- echo '<h1>phpMyEdit error: ',htmlspecialchars($message),'</h1>',"\n";
- if ($additional_info != '') {
- echo '<hr>',htmlspecialchars($additional_info);
- }
- return false;
- } /* }}} */
- /*
- * Database connection function
- */
- function connect() /* {{{ */
- {
- if (!isset($this->db)) {
- $this->error('no database defined');
- return false;
- }
- if (!isset ($this->tb)) {
- $this->error('no table defined');
- return false;
- }
- if ($this->dbh = @mysql_pconnect($this->hn, $this->un, $this->pw)) {
- } else {
- $this->error('could not connect to MySQL');
- return false;
- }
- return true;
- } /* }}} */
- /*
- * Database disconnection function
- */
- function disconnect() /* {{{ */
- {
- @mysql_close($this->dbh);
- unset($this->dbh);
- } /* }}} */
- /*
- * The workhorse
- */
- function execute() /* {{{ */
- {
- // DEBUG - uncomment to enable
- /*
- //phpinfo();
- $this->print_get_vars();
- $this->print_post_vars();
- $this->print_vars();
- echo "<pre>query opts:\n";
- echo print_r($this->query_opts);
- echo "</pre>\n";
- echo "<pre>\n";
- echo 'qfn: ' . print_r($this->fds);
- echo "</pre>\n";
- $fd = $this->fds[27];
- $fn = $this->get_cgi_var($fd);
- echo "<pre>\n";
- echo $this->fds[27] . ': ' . $fn;
- echo "</pre>\n";
- echo "<pre>get vars:\n";
- echo print_r($this->get_opts);
- echo "</pre>\n";
- */
- // Let's do explicit quoting - it's safer
- set_magic_quotes_runtime(0);
- // Checking if language file inclusion was successful
- if (! is_array($this->labels)) {
- $this->error('could not locate language files', 'searched path: '.$this->dir['lang']);
- return false;
- }
- // Database connection
- if ($this->connect() == false) {
- return false;
- }
- /*
- * ======================================================================
- * Pass 3: process any updates generated if the user has selected
- * a save button during Pass 2
- * ======================================================================
- */
- if ($this->saveadd == $this->labels['Save']) {
- $this->add_enabled() && $this->do_add_record();
- }
- elseif ($this->moreadd == $this->labels['More']) {
- $this->add_enabled() && $this->do_add_record();
- $this->operation = $this->labels['Add']; // to force add operation
- $this->recreate_fdd();
- $this->recreate_displayed();
- }
- elseif ($this->savechange == $this->labels['Save']) {
- $this->change_enabled() && $this->do_change_record();
- }
- elseif ($this->savechange == $this->labels['Save']) {
- $this->change_enabled() && $this->do_change_record();
- }
- elseif ($this->adminchange == $this->labels['Save']) {
- $this->change_enabled() && $this->do_change_record();
- }
- elseif ($this->morechange == $this->labels['Apply']) {
- $this->change_enabled() && $this->do_change_record();
- $this->operation = $this->labels['Change']; // to force change operation
- $this->recreate_fdd();
- $this->recreate_displayed();
- }
- elseif ($this->mailchange == $this->labels['Mail']) {
- }
- elseif ($this->rtfgen_detail == $this->labels['Print']) {
- }
- elseif ($this->docchange == $this->labels['Document']) {
- }
- elseif ($this->savedelete == $this->labels['Delete']) {
- $this->delete_enabled() && $this->do_delete_record();
- }
- /*
- * ======================================================================
- * Pass 2: display an input/edit/confirmation screen if the user has
- * selected an editing button on Pass 1 through this page
- * ======================================================================
- */
- if ($this->add_operation()
- || $this->change_operation() || $this->delete_operation()
- || $this->view_operation() || $this->copy_operation()) {
- $this->display_record();
- }
- /*
- * ======================================================================
- * Pass 1 and Pass 3: display the MySQL table in a scrolling window on
- * the screen (skip this step in 'Add More' mode)
- * ======================================================================
- */
- else {
- $this->list_table();
- }
- $this->disconnect();
- if ($this->display['time'] && $this->timer != null) {
- echo $this->timer->end(),' miliseconds';
- }
- } /* }}} */
- /*
- * Class constructor
- */
- function phpMyEdit($opts) /* {{{ */
- {
- // Set desirable error reporting level
- $error_reporting = @error_reporting(E_ALL & ~E_NOTICE);
- // Instance class variables
- $this->hn = $opts['hn'];
- $this->un = $opts['un'];
- $this->pw = $opts['pw'];
- $this->db = $opts['db'];
- $this->tb = $opts['tb'];
- $this->key = $opts['key'];
- $this->key_type = $opts['key_type'];
- $this->inc = $opts['inc'];
- $this->options = $opts['options'];
- $this->fdd = $opts['fdd'];
- $this->multiple = intval($opts['multiple']);
- $this->multiple <= 0 && $this->multiple = 2;
- $this->filters = @$opts['filters'];
- $this->triggers = @$opts['triggers'];
- $this->notify = @$opts['notify'];
- $this->logtable = @$opts['logtable'];
- $this->page_name = @$opts['page_name'];
- if (! isset($this->page_name)) {
- $this->page_name = basename($this->get_server_var('PHP_SELF'));
- isset($this->page_name) || $this->page_name = $this->tb;
- }
- $this->display['query'] = @$opts['display']['query'];
- $this->display['sort'] = @$opts['display']['sort'];
- $this->display['time'] = @$opts['display']['time'];
- if ($this->display['time']) {
- $this->timer = new phpMyEdit_timer();
- }
- $this->display['tabs'] = isset($opts['display']['tabs'])
- ? $opts['display']['tabs'] : true;
- $this->display['form'] = isset($opts['display']['form'])
- ? $opts['display']['form'] : true;
- // Creating directory variables
- $this->dir['root'] = dirname(realpath(__FILE__))
- . (strlen(dirname(realpath(__FILE__))) > 0 ? '/' : '');
- $this->dir['lang'] = $this->dir['root'].'lang/';
- // Creating URL variables
- $this->url['images'] = 'images/';
- isset($opts['url']['images']) && $this->url['images'] = $opts['url']['images'];
- // CSS classes policy
- $this->css = @$opts['css'];
- !isset($this->css['separator']) && $this->css['separator'] = '-';
- !isset($this->css['prefix']) && $this->css['prefix'] = 'pme';
- !isset($this->css['page_type']) && $this->css['page_type'] = false;
- !isset($this->css['position']) && $this->css['position'] = false;
- !isset($this->css['divider']) && $this->css['divider'] = 2;
- $this->css['divider'] = intval(@$this->css['divider']);
- // Navigation
- $this->navigation = @$opts['navigation'];
- if (! $this->nav_buttons() && ! $this->nav_text_links() && ! $this->nav_graphic_links()) {
- $this->navigation .= 'B'; // buttons are default
- }
- if (! $this->nav_up() && ! $this->nav_down()) {
- $this->navigation .= 'D'; // down position is default
- }
- // Language labels (must go after navigation)
- $this->labels = $this->make_language_labels(isset($opts['language'])
- ? $opts['language'] : $this->get_server_var('HTTP_ACCEPT_LANGUAGE'));
- // CGI variables
- $this->cgi['append'] = @$opts['cgi']['append'];
- $this->cgi['overwrite'] = @$opts['cgi']['overwrite'];
- $this->cgi['persist'] = '';
- if (@is_array($opts['cgi']['persist'])) {
- foreach ($opts['cgi']['persist'] as $key => $val) {
- $this->cgi['persist'] .= '&'.urlencode($key).'='.urlencode($val);
- }
- }
- // Sorting variables
- $this->sfn = $this->get_cgi_var('sfn');
- isset($this->sfn) || $this->sfn = array();
- is_array($this->sfn) || $this->sfn = array($this->sfn);
- isset($opts['sort_field']) || $opts['sort_field'] = array();
- is_array($opts['sort_field']) || $opts['sort_field'] = array($opts['sort_field']);
- $this->sfn = array_merge($this->sfn, $opts['sort_field']);
- #$this->sfn[] = '0'; // this last entry will be replaced in recreate_displayed()
- // Form variables all around
- $this->fl = intval($this->get_cgi_var('fl'));
- $this->fm = intval($this->get_cgi_var('fm'));
- $this->qfn = $this->get_cgi_var('qfn');
- $this->sw = $this->get_cgi_var('sw');
- $this->rec = $this->get_cgi_var('rec', '');
- $this->navop = $this->get_cgi_var('navop');
- if (($this->navfm = $this->get_cgi_var('navfmup', $this->fm)) != $this->fm) {
- $this->navop = $this->labels['Go to'];
- } else if (($this->navfm = $this->get_cgi_var('navfmdown', $this->navfm)) != $this->fm) {
- $this->navop = $this->labels['Go to'];
- }
- $this->operation = $this->get_cgi_var('operation');
- $this->saveadd = $this->get_cgi_var('saveadd');
- $this->moreadd = $this->get_cgi_var('moreadd');
- $this->canceladd = $this->get_cgi_var('canceladd');
- $this->savechange = $this->get_cgi_var('savechange');
- $this->adminchange = $this->get_cgi_var('adminchange');
- $this->morechange = $this->get_cgi_var('morechange');
- $this->mailchange = $this->get_cgi_var('mailchange');
- $this->docchange = $this->get_cgi_var('docchange');
- $this->rtfgen_detail = $this->get_cgi_var('rtfgen_detail');
- $this->cancelchange = $this->get_cgi_var('cancelchange');
- $this->savedelete = $this->get_cgi_var('savedelete');
- $this->canceldelete = $this->get_cgi_var('canceldelete');
- $this->cancelview = $this->get_cgi_var('cancelview');
- // Filter setting
- if (isset($this->sw)) {
- $this->sw == $this->labels['Search'] && $this->fl = 1;
- $this->sw == $this->labels['Hide'] && $this->fl = 0;
- //$this->sw == $this->labels['Clear'] && $this->fl = 0;
- }
- // TAB names
- $this->tabs = array();
- // Setting key_delim according to key_type
- if ($this->key_type == 'real') {
- /* If 'real' key_type does not work,
- try change MySQL datatype from float to double */
- $this->rec = doubleval($this->rec);
- $this->key_delim = '';
- } elseif ($this->key_type == 'int') {
- $this->rec = intval($this->rec);
- $this->key_delim = '';
- } else {
- $this->key_delim = '"';
- // $this->rec remains unmodified
- }
- // Specific $fdd modifications depending on performed action
- $this->recreate_fdd();
- // Extract SQL Field Names and number of fields
- $this->recreate_displayed();
- // Gathering query options
- $this->gather_query_opts();
- // Call to action
- !isset($opts['execute']) && $opts['execute'] = 1;
- $opts['execute'] && $this->execute();
- // Restore original error reporting level
- @error_reporting($error_reporting);
- } /* }}} */
- }
- /* Modeline for ViM {{{
- * vim:set ts=4:
- * vim600:fdm=marker fdl=0 fdc=0:
- * }}} */
- ?>
|