action.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. <?php
  2. require_once __DIR__.DIRECTORY_SEPARATOR."common.php";
  3. if(!isset($_['action'])) throw new Exception('Action inexistante');
  4. //Execution du code en fonction de l'action
  5. switch ($_['action']){
  6. case 'login':
  7. global $myUser;
  8. try{
  9. $myUser = User::check($_['login'],$_['password']);
  10. if(!$myUser->connected()) throw new Exception('Utilisateur inexistant');
  11. $_SESSION['currentUser'] = serialize($myUser);
  12. }catch(Exception $e){
  13. $_SESSION['error'] = $e->getMessage();
  14. }
  15. header('location: index.php');
  16. break;
  17. case 'logout':
  18. unset($_SESSION['currentUser']);
  19. session_destroy();
  20. header('location: index.php');
  21. break;
  22. case 'save_user':
  23. try{
  24. global $myUser;
  25. if(!$myUser->connected()) throw new Exception("Permission refusée, seul un connecté peux faire ça");
  26. if($myUser->id!=$_['id']) throw new Exception("Permission refusée, seul le propriétaire du compte peux faire ça");
  27. if($_['password']!=$_['confirmPassword']) throw new Exception("Les deux mot de passe ne correspondent pas");
  28. $myUser->password = User::password_encrypt($_['password']);
  29. $myUser->save();
  30. $_SESSION['success'] = "Mot de passe modifié avec succès";
  31. }catch(Exception $e){
  32. $_SESSION['error'] = $e->getMessage();
  33. }
  34. header('location: account.php');
  35. break;
  36. // SKETCH
  37. case 'create_sketch':
  38. Action::write(function($_,&$response){
  39. global $myUser;
  40. if(!$myUser->connected()) throw new Exception("Permission refusée, seul un connecté peux faire ça");
  41. $sketch = new Sketch();
  42. $sketch->fromArray($_);
  43. $sketch->owner = $myUser->id;
  44. $sketch->save();
  45. $resource = new Resource();
  46. $resource->label = 'README';
  47. $resource->type = 'readme';
  48. $resource->sketch = $sketch->id;
  49. $resource->content = 'Décrivez votre projet ici...';
  50. $resource->sort = 0;
  51. $resource->save();
  52. $response = $sketch->toArray();
  53. });
  54. break;
  55. case 'export_sketch':
  56. global $myUser;
  57. $response = array();
  58. try{
  59. $sketch = Sketch::getById($_['id']);
  60. if(!$sketch->public)throw new Exception('Ce sketch est privé');
  61. $response['sketch'] = $sketch->toArray();
  62. $response['resources'] = array();
  63. foreach(Resource::loadAll(array('sketch'=>$_['id'])) as $resource):
  64. $resource = $resource->toArray();
  65. if($resource['type']=='image'){
  66. $resource['content'] = base64_encode(file_get_contents(SKETCH_PATH.$resource['content']));
  67. }else if($resource['type']=='part'){
  68. $resource['content'] = array();
  69. foreach(ResourcePart::loadAll(array('resource'=>$resource['id'])) as $resourcePart):
  70. $part = $resourcePart->part_object;
  71. $part = $part->toArray();
  72. $resourcePart = $resourcePart->toArray();
  73. if($part['image']!='') $part['image'] = base64_encode(file_get_contents(PART_PATH.$part['image']));
  74. $resource['content'][] = array('resourcePart'=>$resourcePart,'part'=>$part);
  75. endforeach;
  76. }else{
  77. $resource['content'] = htmlspecialchars(SKETCH_PATH.$resource['content']);
  78. }
  79. $response['resources'][] = $resource;
  80. endforeach;
  81. }catch(Exception $e){
  82. $response['error'] = $e->getMessage();
  83. }
  84. $response = gzdeflate(json_encode($response));
  85. if(!isset($_['api'])){
  86. $filename = slugify($sketch->label).('.export.').date('d-m-Y_H-i').'.json';
  87. header("Content-Type: application/json");
  88. header("Content-Length: " . strlen($response));
  89. header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
  90. header('Cache-Control: no-store, no-cache, must-revalidate');
  91. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  92. header('Cache-Control: post-check=0, pre-check=0', FALSE);
  93. header('Pragma: no-cache');
  94. header("Content-Disposition: attachment; filename=\"".$filename."\"");
  95. }
  96. echo $response;
  97. break;
  98. case 'import_sketch':
  99. Action::write(function($_,&$response){
  100. global $myUser;
  101. if(!$myUser->connected()) throw new Exception("Permission refusée, seul un connecté peux faire ça");
  102. if($_['from'] == 'url'){
  103. if(!isset($_['url']) || empty($_['url'])) throw new Exception("Adresse du sketch invalide");
  104. $url = parse_url($_['url']);
  105. parse_str($url['query'], $parameters);
  106. if(!isset($parameters['id']) || empty($parameters['id']) || !is_numeric($parameters['id'])) throw new Exception("ID du sketch invalide");
  107. $contentPath = $url['scheme'].'://'.$url['host'].'/'.substr($url['path'],0,-11).'/action.php?action=export_sketch&id='.$parameters['id'].'&api=true';
  108. }else{
  109. $ext = getExt($_FILES['file']['name']);
  110. if($ext!='json') throw new Exception('Extension JSON autorisée uniquement');
  111. $contentPath = $_FILES['file']['tmp_name'];
  112. }
  113. $stream = false;
  114. try{ $stream = @file_get_contents($contentPath); }catch(Exception $a){}
  115. if($stream === false) throw new Exception("Impossible d'atteindre le contenu hackpoint : $contentPath ");
  116. $stream = gzinflate($stream);
  117. if($stream === false) throw new Exception('Impossible de décompresser le sketch...');
  118. $json = json_decode($stream,true);
  119. if($json == false) throw new Exception('Impossible de parser la réponse du hackpoint, json invalide :'.$stream);
  120. if(isset($json['error'])) throw new Exception($json['error']);
  121. $sketch = new Sketch();
  122. $sketch->fromArray($json['sketch']);
  123. $sketch->id = null;
  124. $sketch->owner = $myUser->id;
  125. $sketch->public = 0;
  126. $sketch->label = $sketch->label .='-import-'.date('d/m/Y H:i');
  127. $sketch->save();
  128. foreach($json['resources'] as $res):
  129. $resource = new Resource();
  130. $resource->fromArray($res);
  131. $resource->id = null;
  132. $resource->sketch = $sketch->id;
  133. $stream = '';
  134. if($resource->type=='image'){
  135. $stream = base64_decode($resource->content);
  136. $resource->content = '';
  137. }
  138. if($resource->type=='part'){
  139. $parts = $resource->content;
  140. $resource->content = '';
  141. }
  142. if(is_string($resource->content)){
  143. $resource->content = htmlspecialchars_decode($resource->content);
  144. }
  145. $resource->save();
  146. if($resource->type=='image'){
  147. $resource->content = $resource->id.'.png';
  148. file_put_contents(SKETCH_PATH.$resource->content,$stream);
  149. $resource->save();
  150. }else if($resource->type=='part'){
  151. foreach($parts as $p):
  152. $part = new Part();
  153. $part->fromArray($p['part']);
  154. $part->id = null;
  155. $stream = base64_decode($part->image);
  156. $part->owner = $myUser->id;
  157. $part->save();
  158. $name = $part->id.'.png';
  159. file_put_contents(PART_PATH.$name,$stream);
  160. $part->image = $name;
  161. $part->save();
  162. $resourcePart = new ResourcePart();
  163. $resourcePart->fromArray($p['resourcePart']);
  164. $resourcePart->part = $part->id;
  165. $resourcePart->resource = $resource->id;
  166. $resourcePart->save();
  167. endforeach;
  168. $resource->content = '';
  169. $resource->save();
  170. }
  171. endforeach;
  172. });
  173. break;
  174. case 'search_sketch':
  175. Action::write(function($_,&$response){
  176. global $myUser;
  177. $sketchs = Sketch::loadAll(array('owner'=>$myUser->id));
  178. foreach($sketchs as $sketch){
  179. $sketch->label = html_entity_decode($sketch->label);
  180. $response['rows'][] = $sketch->toArray();
  181. }
  182. });
  183. break;
  184. case 'delete_sketch':
  185. Action::write(function($_,&$response){
  186. global $myUser;
  187. $sketch = Sketch::getById($_['id']);
  188. if($myUser->id != $sketch->owner) throw new Exception("Permission refusée, seul l'auteur du sketch peux faire ça");
  189. Part::staticQuery("delete FROM ".ResourcePart::tableName()." WHERE resource IN(SELECT id FROM ".Resource::tableName()." WHERE sketch=".$_['id'].") ");
  190. foreach(Resource::loadAll(array('sketch'=>$_['id'])) as $resource):
  191. $resource->remove();
  192. endforeach;
  193. Sketch::deleteById($_['id']);
  194. });
  195. break;
  196. case 'save_sketch_title':
  197. Action::write(function($_,&$response){
  198. global $myUser;
  199. $sketch = Sketch::getById($_['id']);
  200. if($myUser->id != $sketch->owner) return;
  201. $sketch->fromArray($_);
  202. $sketch->save();
  203. });
  204. break;
  205. case 'toggle_share_sketch':
  206. Action::write(function($_,&$response){
  207. global $myUser;
  208. $sketch = Sketch::getById($_['id']);
  209. if($myUser->id != $sketch->owner) throw new Exception("Permission refusée, seul l'auteur du sketch peux faire ça");
  210. $sketch->public = $_['state'];
  211. $sketch->save();
  212. });
  213. break;
  214. case 'download_sketch':
  215. $sketch = Sketch::getByid($_['id']);
  216. $resources = Resource::loadAll(array('sketch'=>$sketch->id),'sort');
  217. $filename = $sketch->slug.'-'.time().'.zip';
  218. $filepath = sys_get_temp_dir().DIRECTORY_SEPARATOR.$filename;
  219. $zip = new ZipArchive;
  220. $res = $zip->open($filepath, ZipArchive::CREATE);
  221. if ($res === TRUE) {
  222. foreach($resources as $resource){
  223. $type = Type::get($resource->type);
  224. $file = Type::toFileStream($resource);
  225. $zip->addFromString($file->name, $file->content);
  226. }
  227. $zip->close();
  228. }
  229. header("Content-Type: application/zip");
  230. header("Content-Length: " . filesize($filepath));
  231. header('Expires: Sun, 01 Jan 2014 00:00:00 GMT');
  232. header('Cache-Control: no-store, no-cache, must-revalidate');
  233. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  234. header('Cache-Control: post-check=0, pre-check=0', FALSE);
  235. header('Pragma: no-cache');
  236. header("Content-Disposition: attachment; filename=\"".$filename."\"");
  237. readfile($filepath);
  238. unlink($filepath);
  239. break;
  240. // RESOURCES
  241. case 'upload_resource':
  242. Action::write(function($_,&$response){
  243. global $myUser;
  244. $resource = Resource::getByid($_['id']);
  245. $sketch = Sketch::getById($resource->sketch);
  246. $ext = getExt($_FILES['file']['name']);
  247. if($myUser->id != $sketch->owner) throw new Exception("Seul le propriétaire du sketch peux faire ça");
  248. if(!in_array($ext,explode(',',ALLOWED_RESOURCE_IMAGE))) throw new Exception('Extensions autorisées '.ALLOWED_RESOURCE_IMAGE);
  249. if($_FILES['file']['size']>ALLOWED_RESOURCE_SIZE) throw new Exception('Taille maximum autorisée '.ALLOWED_RESOURCE_SIZE.' o');
  250. $name = $resource->id.'.'.$ext;
  251. $path = SKETCH_PATH.$name;
  252. move_uploaded_file($_FILES['file']['tmp_name'], $path);
  253. $resource->content = $name;
  254. $resource->save();
  255. $response['url'] = $path.'?v='.time();
  256. });
  257. break;
  258. case 'search_resources':
  259. Action::write(function($_,&$response){
  260. if(!isset($_['id']) || !is_numeric($_['id'])) throw new Exception("Sketch non spécifié");
  261. $resources = Resource::loadAll(array('sketch'=>$_['id']),'sort');
  262. foreach($resources as $resource){
  263. $resource->label = html_entity_decode($resource->label);
  264. $resource->content = null;
  265. $response['rows'][] = $resource->toArray();
  266. }
  267. });
  268. break;
  269. case 'import_resource':
  270. global $myUser;
  271. $sketch = Sketch::getByid($_['id']);
  272. if($myUser->id != $sketch->owner) return;
  273. $ext = explode('.',$_FILES['file']['name']);
  274. $ext = strtolower(array_pop($ext));
  275. $types = Type::all();
  276. $type = 'readme';
  277. foreach($types as $uid=>$tp)
  278. if(isset($tp['extension']) && $ext == $tp['extension']) $type = $uid;
  279. $resource = new Resource();
  280. $resource->sketch = $sketch->id;
  281. $stream = file_get_contents($_FILES['file']['tmp_name']);
  282. $resource->label = $_FILES['file']['name'];
  283. $resource->type = $type;
  284. switch($type){
  285. case 'arduino':
  286. case 'php':
  287. case 'python':
  288. case 'c':
  289. case 'java':
  290. case 'readme':
  291. $resource->content = file_get_contents($_FILES['file']['tmp_name']);
  292. $enc = mb_detect_encoding($resource->content,"UTF-8, ISO-8859-1, GBK");
  293. if($enc!='UTF-8')
  294. $resource->content = iconv($enc,"utf-8",$resource->content);
  295. $resource->save();
  296. break;
  297. case 'image':
  298. $resource->save();
  299. $name = $resource->id.'.'.$ext;
  300. file_put_contents(SKETCH_PATH.$name,$stream);
  301. $resource->content = $name;
  302. $resource->save();
  303. break;
  304. default:
  305. break;
  306. }
  307. break;
  308. //COMPONENT
  309. case 'upload_component_image':
  310. global $myUser;
  311. $ext = explode('.',$_FILES['file']['name']);
  312. $ext = strtolower(array_pop($ext));
  313. if(!in_array($ext,array('jpg','png','jpeg','gif'))) exit();
  314. imageResize($_FILES['file']['tmp_name'],100,100);
  315. echo 'data:image/png;base64,'.base64_encode(file_get_contents($_FILES['file']['tmp_name']));
  316. break;
  317. case 'search_component':
  318. Action::write(function($_,&$response){
  319. global $myUser;
  320. $parts = Part::populate();
  321. foreach($parts as $part){
  322. $part->label = html_entity_decode($part->label);
  323. $part->link = html_entity_decode($part->link);
  324. if($part->image==''){
  325. $part->image = 'img/default_image.png';
  326. }else{
  327. $part->image = PART_PATH.html_entity_decode($part->image);
  328. }
  329. $response['rows'][] = $part->toArray();
  330. }
  331. });
  332. break;
  333. case 'delete_component':
  334. Action::write(function($_,&$response){
  335. global $myUser;
  336. $part = Part::getById($_['id']);
  337. if($myUser->id!=$part->owner) throw new Exception('Seul le propriétaire du composant peux faire ça');
  338. $part->remove();
  339. });
  340. break;
  341. case 'save_component':
  342. Action::write(function($_,&$response){
  343. global $myUser;
  344. if(!$myUser->connected()) throw new Exception("Permission refusée, seul un connecté peux faire ça");
  345. $part = isset($_['id']) && is_numeric($_['id'])?Part::getById($_['id']):new Part();
  346. $part->fromArray($_);
  347. $part->owner = $myUser->id;
  348. $part->save();
  349. if(substr($part->image,0,10) == 'data:image'){
  350. $imageName = $part->id.'.png';
  351. base64_to_image($part->image,PART_PATH.$imageName);
  352. $part->image = $imageName;
  353. $part->save();
  354. }
  355. $response = $part->toArray();
  356. });
  357. break;
  358. case 'edit_component':
  359. Action::write(function($_,&$response){
  360. $part = isset($_['id'])? Part::getById($_['id']):new Part;
  361. $part->label = html_entity_decode($part->label);
  362. $part->link = html_entity_decode($part->link);
  363. $part->brand = html_entity_decode($part->brand);
  364. if($part->image==''){
  365. $part->image = 'img/default_image.png';
  366. }else{
  367. $part->image = PART_PATH.html_entity_decode($part->image);
  368. }
  369. $part->image.='?t='.time();
  370. $response = $part->toArray();
  371. });
  372. break;
  373. //RESOURCE
  374. case 'save_resource':
  375. Action::write(function($_,&$response){
  376. global $myUser;
  377. $sketch = Sketch::getById($_['sketch']);
  378. if($myUser->id != $sketch->owner) throw new Exception("Permission refusée, seul l'auteur du sketch peux faire ça");
  379. $resource = isset($_['id']) && is_numeric($_['id']) && !empty($_['id']) ? Resource::getByid($_['id']) : new Resource();
  380. $resource->fromArray($_);
  381. $resource->sort = 10;
  382. if($resource->type=='readme' && $resource->id==0) $resource->sort = 0;
  383. $resource->label = $resource->label == ''?'Sans titre '.date('d-m-Y H:i'):$resource->label;
  384. $resource->save();
  385. $response = $resource->toArray();
  386. });
  387. break;
  388. case 'save_resource_content':
  389. Action::write(function($_,&$response){
  390. global $myUser;
  391. $resource = Resource::getByid($_['id']);
  392. $sketch = Sketch::getById($resource->sketch);
  393. if($myUser->id != $sketch->owner) return;
  394. $resource->fromArray($_);
  395. $resource->save();
  396. });
  397. break;
  398. case 'edit_resource':
  399. Action::write(function($_,&$response){
  400. $resource = Resource::getById($_['id']);
  401. global $myUser;
  402. $sketch = Sketch::getById($resource->sketch);
  403. $resource->label = html_entity_decode($resource->label);
  404. $response = $resource->toArray();
  405. $type = Type::get($resource->type);
  406. switch($resource->type){
  407. case 'image':
  408. if($myUser->id == $sketch->owner){
  409. $image = $response['content']==''?'img/default_image.png':SKETCH_PATH.$response['content'].'?v='.time();
  410. $response['content'] = '<img style="width:100%;height:auto;" class="dropzone" src="'.$image.'" />';
  411. $response['upload'] = $type['upload'];
  412. }
  413. break;
  414. case 'part':
  415. $response['callback'] = 'init_part();';
  416. $response['content'] = '<table class="table table-stripped table-bordered" id="parts"><thead>
  417. <tr>
  418. <th>Libellé</th>
  419. <!--<th>Lien</th>
  420. <th>Prix</th>-->';
  421. if($myUser->id == $sketch->owner)
  422. $response['content'] .= '<th></th>';
  423. $response['content'] .= '</tr>';
  424. if($myUser->id == $sketch->owner){
  425. $response['content'] .= '<tr id="partForm" data-action="save_part" data-id="">
  426. <td><input type="text" id="label" class="form-control"></td>
  427. <!--<td><input type="url" id="link" class="form-control"></td>
  428. <td><input type="text" id="price" class="form-control input-mini"></td>-->
  429. <td><div class="btn btn-success" onclick="save_part();"><i class="fa fa-plus"></i></div></td>
  430. </tr>';
  431. }
  432. $response['content'] .= '</thead><tbody>';
  433. $response['content'] .= '<tr style="display:none" data-id="{{id}}">
  434. <td ><a href="{{link}}"><div class="componentImage"><img src="{{image}}"/></div> {{label}}</a> {{#price}}<code>{{price}} €</code>{{/price}}{{#brand}} <small>{{brand}}</small>{{/brand}}</td>';
  435. if($myUser->id == $sketch->owner)
  436. $response['content'] .= '<td><div class="btn btn-danger" onclick="delete_part(this);"><i class="fa fa-times" ></i></div></td>';
  437. $response['content'] .= '</tr>';
  438. $response['content'] .='</tbody></table>';
  439. break;
  440. }
  441. //for sources
  442. if(isset($type['codemirror'])){
  443. $response['content'] = '<textarea>'.$response['content'].'</textarea>';
  444. $response['code'] = $type['codemirror'];
  445. if($myUser->id != $sketch->owner) $response['code']['readOnly'] = true;
  446. }
  447. });
  448. break;
  449. case 'delete_resource':
  450. Action::write(function($_,&$response){
  451. global $myUser;
  452. $resource = Resource::getById($_['id']);
  453. $sketch = Sketch::getById($resource->sketch);
  454. if($myUser->id != $sketch->owner) throw new Exception("Permission refusée, seul l'auteur du sketch peux faire ça");
  455. Resource::getById($_['id']);
  456. $resource->remove();
  457. });
  458. break;
  459. /*PART*/
  460. case 'search_part':
  461. Action::write(function($_,&$response){
  462. if(!isset($_['id']) || !is_numeric($_['id'])) throw new Exception("Ressource non spécifiée");
  463. $resourceParts = ResourcePart::loadAll(array('resource'=>$_['id']),'sort');
  464. foreach($resourceParts as $resourcePart):
  465. $part = $resourcePart->part_object;
  466. $part->label = html_entity_decode($part->label);
  467. $part->link = html_entity_decode($part->link);
  468. if($part->image == '') {
  469. $part->image = 'img/default_image.png';
  470. }else{
  471. $part->image = PART_PATH.$part->image;
  472. }
  473. $line = $part->toArray();
  474. $line['id'] = $resourcePart->id;
  475. $response['rows'][] = $line;
  476. endforeach;
  477. });
  478. break;
  479. case 'delete_part':
  480. Action::write(function($_,&$response){
  481. global $myUser;
  482. $part = ResourcePart::getById($_['id']);
  483. $resource = $part->resource_object;
  484. $sketch = $resource->sketch_object;
  485. if($myUser->id != $sketch->owner) throw new Exception("Permission refusée, seul l'auteur du sketch peux faire ça");
  486. ResourcePart::deleteById($_['id']);
  487. });
  488. break;
  489. case 'save_part':
  490. Action::write(function($_,&$response){
  491. global $myUser;
  492. $model = isset($_['model']) && is_numeric($_['model']) && !empty($_['model']) ? Part::getByid($_['model']) : new Part();
  493. if($model->id==0){
  494. $model->fromArray($_);
  495. $model->save();
  496. }
  497. $resourcePart = new ResourcePart();
  498. $resourcePart->fromArray($_);
  499. $resourcePart->part = $model->id;
  500. $resourcePart->save();
  501. });
  502. break;
  503. case 'autocomplete_part':
  504. global $myUser;
  505. $parts = Part::staticQuery("SELECT DISTINCT label,* FROM ".Part::tableName()." WHERE label LIKE ? GROUP BY label ORDER BY price ASC ",array('%'.$_['term'].'%'),true);
  506. $rows = array();
  507. levenshtein_deduplication($parts);
  508. foreach($parts as $part):
  509. $part->image = PART_PATH.$part->image;
  510. $rows[] = array('label'=>$part->label.' ('.$part->price.'€)','value'=>$part->toArray());
  511. endforeach;
  512. echo json_encode($rows);
  513. break;
  514. default:
  515. break;
  516. }
  517. function levenshtein_deduplication(&$objs){
  518. foreach($objs as $obj1):
  519. foreach($objs as $u=>$obj2):
  520. if($obj1->id==$obj2->id) continue;
  521. if(levenshtein($obj1->label,$obj2->label) < 5 )
  522. unset($objs[$u]);
  523. endforeach;
  524. endforeach;
  525. }
  526. ?>