PageRenderTime 48ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/pragma/datatransfer/importkit/magmi/magmi/web/magmi_profile_panel.php

https://bitbucket.org/deniskulikouski/belvg.deniska
PHP | 514 lines | 466 code | 45 blank | 3 comment | 44 complexity | 630a05d7607722cc5a32dbd74410eed5 MD5 | raw file
Possible License(s): LGPL-3.0
  1. <?php
  2. if(isset($_REQUEST["profile"]))
  3. {
  4. $profile=$_REQUEST["profile"];
  5. }
  6. else
  7. {
  8. if(isset($_SESSION["last_runned_profile"]))
  9. {
  10. $profile=$_SESSION["last_runned_profile"];
  11. }
  12. }
  13. if($profile=="")
  14. {
  15. $profile="default";
  16. }
  17. $profilename=($profile!="default"?$profile:"Default");
  18. ?>
  19. <script type="text/javascript">
  20. var profile="<?php echo $profile?>";
  21. </script>
  22. <script type="text/javascript">
  23. </script>
  24. <div class="container_12" id="profile_action">
  25. <div class="grid_12 subtitle"><span>Configure Current Profile (<?php echo $profilename?>)</span>
  26. <?php
  27. $eplconf=new EnabledPlugins_Config($profile);
  28. $eplconf->load();
  29. $conf_ok=$eplconf->hasSection("PLUGINS_DATASOURCES");
  30. ?>
  31. <span class="saveinfo<?php if(!$conf_ok){?> log_warning<?php }?>" id="profileconf_msg">
  32. <?php if($conf_ok){?>
  33. Saved:<?php echo $eplconf->getLastSaved("%c")?>
  34. <?php }
  35. else{?>
  36. <?php echo $profilename?> Profile Config not saved yet
  37. <?php
  38. }?>
  39. </span>
  40. </div>
  41. <div class="grid_12 col">
  42. <form action="magmi_chooseprofile.php" method="POST" id="chooseprofile" >
  43. <h3>Profile to configure</h3>
  44. <ul class="formline">
  45. <li class="label">Current Magmi Profile:</li>
  46. <li class="value">
  47. <select name="profile" onchange="$('chooseprofile').submit()">
  48. <option <?php if(null==$profile){?>selected="selected"<?php }?> value="default">Default</option>
  49. <?php foreach($profilelist as $profname){?>
  50. <option <?php if($profname==$profile){?>selected="selected"<?php }?> value="<?php echo $profname?>"><?php echo $profname?></option>
  51. <?php }?>
  52. </select>
  53. </li>
  54. </ul>
  55. <ul class="formline">
  56. <li class="label">Copy Selected Profile to:</li>
  57. <li class="value"><input type="text" name="newprofile"></input></li>
  58. </ul>
  59. <input type="submit" value="Copy Profile &amp; switch"></input>
  60. <?php
  61. require_once("magmi_pluginhelper.php");
  62. $order=array("datasources","general","itemprocessors");
  63. $plugins=Magmi_PluginHelper::getInstance('main')->getPluginClasses($order);
  64. $pcats=array();
  65. foreach($plugins as $k=>$pclasslist)
  66. {
  67. foreach($pclasslist as $pclass)
  68. {
  69. //invoke static method, using call_user_func (5.2 compat mode)
  70. $pcat=call_user_func(array($pclass,"getCategory"));
  71. if(!isset($pcats[$pcat]))
  72. {
  73. $pcats[$pcat]=array();
  74. }
  75. $pcats[$pcat][]=$pclass;
  76. }
  77. }
  78. ?>
  79. </form>
  80. </div>
  81. </div>
  82. <div class="container_12" id="profile_cfg">
  83. <form action="" method="POST" id="saveprofile_form">
  84. <input type="hidden" name="profile" id="curprofile" value="<?php echo $profile?>">
  85. <?php foreach($order as $k)
  86. {?>
  87. <input type="hidden" id="plc_<?php echo strtoupper($k)?>" value="<?php echo implode(",",$eplconf->getEnabledPluginClasses($k))?>" name="PLUGINS_<?php echo strtoupper($k)?>:classes"></input>
  88. <div class="grid_12 col <?php if($k==$order[count($order)-1]){?>omega<?php }?>">
  89. <h3><?php echo ucfirst($k)?></h3>
  90. <?php if($k=="datasources")
  91. {?>
  92. <?php $pinf=$plugins[$k];?>
  93. <?php if(count($pinf)>0){?>
  94. <div class="pluginselect" style="float:left">
  95. <select name="PLUGINS_DATASOURCES:class" class="pl_<?php echo $k?>">
  96. <?php
  97. $sinst=null;
  98. foreach($pinf as $pclass)
  99. {
  100. $pinst=Magmi_PluginHelper::getInstance($profile)->createInstance($k,$pclass);
  101. if($sinst==null)
  102. {
  103. $sinst=$pinst;
  104. }
  105. $pinfo=$pinst->getPluginInfo();
  106. if($eplconf->isPluginEnabled($k,$pclass))
  107. {
  108. $sinst=$pinst;
  109. }
  110. ?>
  111. <option value="<?php echo $pclass?>"<?php if($sinst==$pinst){?>selected="selected"<?php }?>><?php echo $pinfo["name"]." v".$pinfo["version"]?></option>
  112. <?php }
  113. ?>
  114. </select>
  115. </div>
  116. <?php if(isset($pinfo["url"])){?>
  117. <div class="plugindoc" >
  118. <a href="<?php echo $pinfo["url"]?>" target="magmi_doc">documentation</a>
  119. </div>
  120. <?php }?>
  121. <div class="pluginconfpanel selected">
  122. <?php echo $sinst->getOptionsPanel()->getHtml();?>
  123. </div>
  124. <?php }else{
  125. $conf_ok=0;
  126. ?>
  127. Magmi needs a datasource plugin, please install one
  128. <?php }?>
  129. <?php
  130. }
  131. else
  132. {
  133. foreach($pcats as $pcat=>$pclasslist) {?>
  134. <?php
  135. $catopen=false;
  136. $pinf=$plugins[$k];?>
  137. <?php foreach($pinf as $pclass) {
  138. if(!in_array($pclass,$pclasslist))
  139. {
  140. continue;
  141. }
  142. else
  143. {?>
  144. <?php if(!$catopen){$catopen=true?>
  145. <div class="grid_12 omega"><h1><?php echo $pcat?></h1>
  146. <?php }?>
  147. <ul>
  148. <?php
  149. $pinst=Magmi_PluginHelper::getInstance($profile)->createInstance($k,$pclass);
  150. $pinfo=$pinst->getPluginInfo();
  151. $info=$pinst->getShortDescription();
  152. $plrunnable=$pinst->isRunnable();
  153. $enabled=$eplconf->isPluginEnabled($k,$pclass)
  154. ?>
  155. <li>
  156. <div class="pluginselect">
  157. <?php if($plrunnable[0]){?>
  158. <input type="checkbox" class="pl_<?php echo $k?>" name="<?php echo $pclass?>" <?php if($eplconf->isPluginEnabled($k,$pclass)){?>checked="checked"<?php }?>>
  159. <?php } else {?>
  160. <input type="checkbox" class="pl_<?php echo $k?>" name="<?php echo $pclass?>" disabled="disabled">
  161. <?php }?>
  162. <span class="pluginname <?php if(isset($pinfo['sponsorinfo'])){ ?> sponsored <?php } ?>" ><?php echo $pinfo["name"]." v".$pinfo["version"];?></span>
  163. </div>
  164. <div class="plugininfo">
  165. <span>info</span>
  166. <div class="plugininfohover">
  167. <div class="plugindata">
  168. <ul>
  169. <?php $sp=isset($pinfo["sponsorinfo"]);
  170. foreach($pinfo as $pik=>$piv)
  171. { ?>
  172. <li <?php if(isset($sp)){ ?> class='sponsored'<?php } ?>><?php
  173. if($pik=="url")
  174. {?>
  175. <span><?php echo $pik?></span>:<span><a href="<?php echo $piv?>" target="_blank">Wiki entry</a></span>
  176. <?php }
  177. else
  178. if($pik=="sponsorinfo")
  179. {
  180. ?>
  181. <span class="sponsor">Sponsored By</span>:
  182. <span>
  183. <?php if(isset($piv['url'])) { ?>
  184. <a href="<?php echo $piv['url']?>" target="_blank">
  185. <?php }
  186. echo $piv["name"];
  187. if(isset($piv['url'])) { ?>
  188. </a>
  189. <?php } ?>
  190. </span>
  191. <?php }
  192. else
  193. {
  194. ?>
  195. <span><?php echo $pik?></span>:<span><?php echo $piv ?></span>
  196. <?php
  197. }
  198. ?>
  199. </li>
  200. <?php }
  201. ?>
  202. </ul>
  203. <div class="minidoc">
  204. <?php echo $info?>
  205. </div>
  206. </div>
  207. <?php if(!$plrunnable[0]){?>
  208. <div class="error">
  209. <pre><?php echo $plrunnable[1]?></pre>
  210. </div>
  211. <?php }?>
  212. </div>
  213. </div>
  214. <div class="pluginconf" <?php if(!$enabled){?>style="display:none"<?php }?>>
  215. <span><a href="javascript:void(0)">configure</a></span>
  216. </div>
  217. <?php if(isset($pinfo["url"])){?>
  218. <div class="plugindoc">
  219. <a href="<?php echo $pinfo["url"]?>" target="magmi_doc">documentation</a>
  220. </div>
  221. <?php }?>
  222. <div class="pluginconfpanel">
  223. <?php if($enabled){echo $pinst->getOptionsPanel()->getHtml();}?>
  224. </div>
  225. </li>
  226. </ul>
  227. <?php }?>
  228. <?php }?>
  229. <?php if($catopen){?></div><?php }?>
  230. <?php }}?>
  231. </div>
  232. <?php }?>
  233. </form>
  234. <div class="grid_12">
  235. <div style="float:right">
  236. <a id="saveprofile" class="actionbutton" href="javascript:void(0)" <?php if(!$conf_ok){?>disabled="disabled"<?php }?>>Save Profile (<?php echo $profilename?>)</a>
  237. </div>
  238. </div>
  239. </div>
  240. <div id="paramchanged" style="display:none">
  241. <div class="subtitle"><h3>Parameters changed</h3></div>
  242. <div class="changedesc"><b>You changed parameters without saving profile , would you like to:</b></div>
  243. <ul>
  244. <li>
  245. <input type="radio" name="paramcr" value="saveprof">Save chosen Profile (<?php echo $profilename ?>) with current parameters
  246. </li>
  247. <li>
  248. <input type="radio" name="paramcr" value="applyp" checked="checked">Apply current parameters as profile override without saving
  249. </li>
  250. <li>
  251. <input type="radio" name="paramcr" value="useold">Discard changes &amp; apply last saved <?php echo $profilename ?> profile values
  252. </li>
  253. </ul>
  254. <div class="actionbuttons">
  255. <a class="actionbutton" href="javascript:handleRunChoice('paramcr',comparelastsaved());" id="paramchangeok">Run with selected option</a>
  256. <a class="actionbutton" href="javascript:cancelimport();" id="paramchangecancel">Cancel Run</a>
  257. </div>
  258. </div>
  259. <div id="pluginschanged" style="display:none">
  260. <div class="subtitle"><h3>Plugin selection changed</h3></div>
  261. <div class="changedesc"><b>You changed selected plugins without saving profile , would you like to:</b></div>
  262. <ul>
  263. <li>
  264. <input type="radio" name="plugselcr" value="saveprof" checked="checked">Save chosen Profile (<?php echo $profilename ?>) with current parameters
  265. </li>
  266. <li>
  267. <input type="radio" name="plugselcr" value="useold">Discard changes &amp; apply last saved <?php echo $profilename ?> profile values
  268. </li>
  269. </ul>
  270. <div class="actionbuttons">
  271. <a class="actionbutton" href="javascript:handleRunChoice('plugselcr',comparelastsaved());" id="plchangeok">Run with selected option</a>
  272. <a class="actionbutton" href="javascript:cancelimport();" id="plchangecancel">Cancel Run</a>
  273. </div>
  274. </div>
  275. <script type="text/javascript">
  276. window.lastsaved={};
  277. handleRunChoice=function(radioname,changeinfo)
  278. {
  279. var changed=changeinfo.changed;
  280. var sval=$$('input:checked[type="radio"][name="'+radioname+'"]').pluck('value');
  281. if(sval=='saveprof')
  282. {
  283. saveProfile(1,function(){$('runmagmi').submit();});
  284. }
  285. if(sval=='useold')
  286. {
  287. $('runmagmi').submit();
  288. }
  289. if(sval=='applyp')
  290. {
  291. changed.each(function(it){
  292. $('runmagmi').insert({bottom:'<input type="hidden" name="'+it.key+'" value="'+it.value+'">'});
  293. });
  294. $('runmagmi').submit();
  295. }
  296. }
  297. cancelimport=function()
  298. {
  299. $('overlay').hide();
  300. }
  301. updatelastsaved=function()
  302. {
  303. gatherclasses(['DATASOURCES','GENERAL','ITEMPROCESSORS']);
  304. window.lastsaved=$H($('saveprofile_form').serialize(true));
  305. };
  306. comparelastsaved=function()
  307. {
  308. gatherclasses(['DATASOURCES','GENERAL','ITEMPROCESSORS']);
  309. var curprofvals=$H($('saveprofile_form').serialize(true));
  310. var changeinfo={changed:false,target:''};
  311. var out="";
  312. var diff={};
  313. changeinfo.target='paramchanged';
  314. curprofvals.each(function(kv)
  315. {
  316. var lastval=window.lastsaved.get(kv.key);
  317. if(kv.value!=lastval)
  318. {
  319. diff[kv.key]=kv.value;
  320. if(kv.key.substr(0,8)=="PLUGINS_")
  321. {
  322. changeinfo.target='pluginschanged';
  323. }
  324. }
  325. });
  326. changeinfo.changed=$H(diff);
  327. if(changeinfo.changed.size()==0)
  328. {
  329. changeinfo.changed=false;
  330. }
  331. return changeinfo;
  332. };
  333. addclass=function(it,o)
  334. {
  335. if(it.checked){
  336. this.arr.push(it.name);
  337. }
  338. };
  339. gatherclasses=function(tlist)
  340. {
  341. tlist.each(function(t,o){
  342. var context={arr:[]};
  343. $$(".pl_"+t.toLowerCase()).each(addclass,context);
  344. var target=$("plc_"+t);
  345. target.value=context.arr.join(",");
  346. });
  347. };
  348. initConfigureLink=function(maincont)
  349. {
  350. var cfgdiv=maincont.select('.pluginconf');
  351. if(cfgdiv.length>0)
  352. {
  353. cfgdiv=cfgdiv[0];
  354. var confpanel=maincont.select('.pluginconfpanel');
  355. confpanel=confpanel[0]
  356. cfgdiv.stopObserving('click');
  357. cfgdiv.observe('click',function(ev){
  358. confpanel.toggleClassName('selected');
  359. confpanel.select('.ifield').each(function(it){
  360. it.select('.fieldhelp').each(function(fh){
  361. fh.observe('click',function(ev){
  362. it.select('.fieldsyntax').each(function(el){el.toggle();})
  363. });
  364. });
  365. });
  366. });
  367. }
  368. };
  369. showConfLink=function(maincont)
  370. {
  371. var cfgdiv=maincont.select('.pluginconf');
  372. if(cfgdiv.length>0)
  373. {
  374. cfgdiv=cfgdiv[0];
  375. cfgdiv.show();
  376. }
  377. };
  378. loadConfigPanel=function(container,profile,plclass,pltype)
  379. {
  380. new Ajax.Updater({success:container},'ajax_pluginconf.php',
  381. {parameters:{
  382. profile:profile,
  383. plugintype:pltype,
  384. pluginclass:plclass},
  385. evalScripts:true,
  386. onComplete:
  387. function(){
  388. showConfLink($(container.parentNode));
  389. initConfigureLink($(container.parentNode));
  390. }});
  391. };
  392. removeConfigPanel=function(container)
  393. {
  394. var cfgdiv=$(container.parentNode).select('.pluginconf');
  395. cfgdiv=cfgdiv[0];
  396. cfgdiv.stopObserving('click');
  397. cfgdiv.hide();
  398. container.removeClassName('selected');
  399. container.update('');
  400. };
  401. initAjaxConf=function(profile)
  402. {
  403. //foreach plugin selection
  404. $$('.pluginselect').each(function(pls)
  405. {
  406. var del=pls.firstDescendant();
  407. var evname=(del.tagName=="SELECT"?'change':'click');
  408. //check the click
  409. del.observe(evname,function(ev)
  410. {
  411. var el=Event.element(ev);
  412. var plclass=(el.tagName=="SELECT")?el.value:el.name;
  413. var elclasses=el.classNames();
  414. var pltype="";
  415. elclasses.each(function(it){if(it.substr(0,3)=="pl_"){pltype=it.substr(3);}});
  416. var doload=(el.tagName=="SELECT")?true:el.checked;
  417. var targets=$(pls.parentNode).select(".pluginconfpanel");
  418. var container=targets[0];
  419. if(doload)
  420. {
  421. loadConfigPanel(container,profile,plclass,pltype);
  422. }
  423. else
  424. {
  425. removeConfigPanel(container);
  426. }
  427. });
  428. });
  429. };
  430. initDefaultPanels=function()
  431. {
  432. $$('.pluginselect').each(function(it){initConfigureLink($(it.parentNode));});
  433. updatelastsaved();
  434. };
  435. saveProfile=function(confok,onsuccess)
  436. {
  437. gatherclasses(['DATASOURCES','GENERAL','ITEMPROCESSORS']);
  438. updatelastsaved();
  439. new Ajax.Updater('profileconf_msg',
  440. "magmi_saveprofile.php",
  441. {parameters:$('saveprofile_form').serialize('true'),
  442. onSuccess:function(){
  443. if(confok)
  444. {
  445. onsuccess();
  446. }
  447. else
  448. {
  449. $('profileconf_msg').show();
  450. }}
  451. });
  452. };
  453. initAjaxConf('<?php echo $profile?>');
  454. initDefaultPanels();
  455. $('saveprofile').observe('click',function()
  456. {
  457. saveProfile(<?php echo $conf_ok?1:0 ?>,function(){$('chooseprofile').submit();});
  458. });
  459. $('runmagmi').observe('submit',function(ev){
  460. var ls=comparelastsaved();
  461. if(ls.changed!==false)
  462. {
  463. $('overlaycontent').update($(ls.target));
  464. $$('#overlaycontent > div').each(function(el){el.show()});
  465. $('overlay').show();
  466. ev.stop();
  467. }
  468. });
  469. </script>