api.vlanmanagement.php 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254
  1. <?php
  2. /**
  3. * Like IPAM for VLAN
  4. */
  5. class VlanManagement {
  6. const MODULE = '?module=vlanmanagement';
  7. const MODULE_SVLAN = '?module=vlanmanagement&svlan=true';
  8. const MODULE_REALMS = '?module=vlanmanagement&realms=true';
  9. const MODULE_UNIVERSALQINQ = '?module=universalqinq';
  10. const MODULE_ONU_APPLY = '?module=vlanmanagement_onu_apply';
  11. const MODULE_ONU_APPLY_AJAXOLTLIST = '?module=vlanmanagement_onu_apply&ajaxOltList=true';
  12. const EMPTY_SELECTOR_OPTION = '---';
  13. const ARRAY_RANGE_STEP = 1;
  14. const ARRAY_RANGE_START = 1;
  15. const QINQ_OPTION = 'QINQ_ENABLED';
  16. const QINQ_LABEL = 'QINQ for switches';
  17. const VLANMANAGEMENT_OPTION = 'VLAN_MANAGEMENT_ENABLED';
  18. const ONUREG_QINQ_OPTION = 'ONUREG_QINQ_ENABLED';
  19. const UNIVERSAL_QINQ_OPTION = 'UNIVERSAL_QINQ_ENABLED';
  20. const UNIVERSAL_QINQ_RGHT = 'UNIVERSALQINQCONFIG';
  21. const UNIVERSAL_QINQ_LABEL = 'Universal QINQ';
  22. const DEFAULT_SVLAN = 0;
  23. const DEFAULT_REALM = 1;
  24. /**
  25. * Routing URL.
  26. *
  27. * @var string
  28. */
  29. protected $startSvlanUrl = '';
  30. /**
  31. * Routing URL.
  32. *
  33. * @var string
  34. */
  35. protected $startManagementUrl = '';
  36. /**
  37. * Placeholder for nyan_orm instance for realms table.
  38. *
  39. * @var object
  40. */
  41. protected $realmDb;
  42. /**
  43. * Placeholder for nyan_orm instance for qinq_svlan table.
  44. *
  45. * @var object
  46. */
  47. protected $svlanDb;
  48. /**
  49. * Placeholder for nyan_orm instance for qinq_bindings table.
  50. *
  51. * @var object
  52. */
  53. protected $cvlanDb;
  54. /**
  55. * Placeholder for nyan_orm instance for switches_qinq table.
  56. *
  57. * @var object
  58. */
  59. protected $switchesqinqDb;
  60. /**
  61. * Placeholder for nyan_orm instance for switches table.
  62. *
  63. * @var object
  64. */
  65. protected $switchesDb;
  66. /**
  67. * Placeholder for nyan_orm instance for switchmodels table.
  68. *
  69. * @var object
  70. */
  71. protected $switchModelsDb;
  72. /**
  73. * Placeholder for nyan_orm instance for switchportassign table.
  74. *
  75. * @var object
  76. */
  77. protected $switchPortDb;
  78. /**
  79. * Placeholder for nyan_orm instance for zte_qinq table.
  80. *
  81. * @var object
  82. */
  83. protected $zteqinqDb;
  84. /**
  85. * Placeholder for nyan_orm instance for olt_qinq table.
  86. *
  87. * @var object
  88. */
  89. protected $oltqinqDb;
  90. /**
  91. * Placeholder for nyan_orm instance for zte_cards table.
  92. *
  93. * @var object
  94. */
  95. protected $zteCardsDb;
  96. /**
  97. * Contains main configuration file alter.ini
  98. *
  99. * @var array
  100. */
  101. protected $altCfg = array();
  102. /**
  103. * Contains all realms
  104. *
  105. * @var array
  106. */
  107. protected $allRealms = array();
  108. /**
  109. * Contains all svlans
  110. *
  111. * @var array
  112. */
  113. protected $allSvlan = array();
  114. /**
  115. * Contains all errors
  116. *
  117. * @var array
  118. */
  119. public $error = array();
  120. /**
  121. * Contains all exceptions.
  122. *
  123. * @var array
  124. */
  125. public $exceptions = array();
  126. /**
  127. * Placeholder for UbillingMessageHelper instance.
  128. *
  129. * @var object
  130. */
  131. protected $messages;
  132. /**
  133. * Contains default type of vlan allocation.
  134. *
  135. * @var string
  136. */
  137. protected $defaultType;
  138. /**
  139. * Contains all realms to select
  140. *
  141. * @var array
  142. */
  143. protected $realmSelector = array();
  144. /**
  145. * Contains all switches
  146. *
  147. * @var array
  148. */
  149. protected $allSwitches = array();
  150. /**
  151. * Contains all switch models.
  152. *
  153. * @var array
  154. */
  155. protected $allSwitchModels = array();
  156. /**
  157. * Contains all occupied cvlans by customers.
  158. *
  159. * @var array
  160. */
  161. protected $occupiedUniversal = array();
  162. /**
  163. * Contains all occupied cvlans by switches.
  164. *
  165. * @var array
  166. */
  167. protected $occupiedSwitches = array();
  168. /**
  169. * Contains all occupied cvlans by ZTE OLTs
  170. *
  171. * @var array
  172. */
  173. protected $occupiedOltZte = array();
  174. /**
  175. * Contains all occupued cvlans by non ZTE OLTs
  176. *
  177. * @var array
  178. */
  179. protected $occupiedOltNonZte = array();
  180. /**
  181. * Contains all Cvlan => slot number for ceratin OLT.
  182. *
  183. * @var array
  184. */
  185. protected $occupiedOltZteSlot = array();
  186. /**
  187. * Contains all Cvlan => port number for certain zte OLT.
  188. *
  189. * @var array
  190. */
  191. protected $occupiedOltZtePort = array();
  192. /**
  193. * Contains all Cvlan => port number for certain non zte OLT
  194. *
  195. * @var array
  196. */
  197. protected $occupiedOltNonZtePort = array();
  198. /**
  199. * Storing data cvlan = switch id
  200. *
  201. * @var array
  202. */
  203. protected $occupiedOltZteId = array();
  204. /**
  205. * Storing data cvlan = switch id
  206. *
  207. * @var array
  208. */
  209. protected $occupiedOltNonZteId = array();
  210. /**
  211. * Dictionary for pairing cvlan number with switch which occupies this cvlan.
  212. *
  213. * @var array
  214. */
  215. protected $switchVlans = array();
  216. /**
  217. * Contains all assigned ports by users.
  218. *
  219. * @var array
  220. */
  221. protected $switchPortCustomer = array();
  222. /**
  223. * Contains all not assigned ports.
  224. *
  225. * @var array
  226. */
  227. protected $switchPortFree = array();
  228. /**
  229. * Default realm selection
  230. *
  231. * @var mixed
  232. */
  233. public $defaultRealm = 1;
  234. /**
  235. * Default svlan selection.
  236. *
  237. * @var mixed
  238. */
  239. public $defaultSvlan = 1;
  240. /**
  241. * Instance of UbRouting class.
  242. *
  243. * @var object
  244. */
  245. public $routing;
  246. /**
  247. * Array loads from OnuRegister class. Contains all Epon cards.
  248. *
  249. * @var array
  250. */
  251. protected $eponCards = array();
  252. /**
  253. * Array loads from OnuRegister class. Contains all Gpon cards.
  254. *
  255. * @var array
  256. */
  257. protected $gponCards = array();
  258. /**
  259. * Contains all occupied switchports
  260. *
  261. * @var array
  262. */
  263. protected $allPorts = array();
  264. /**
  265. * Contains current svlan_id
  266. *
  267. * @var int
  268. */
  269. protected $svlanId = 0;
  270. public function __construct($svlanId = 0) {
  271. $this->routing = new ubRouting();
  272. $this->messages = new UbillingMessageHelper();
  273. if (!$svlanId) {
  274. $this->svlanId = $this->routing->get('svlan_id', 'int');
  275. } else {
  276. $this->svlanId = $svlanId;
  277. }
  278. $this->initEnv();
  279. $this->dbInit();
  280. $this->loadData();
  281. }
  282. /**
  283. * Create all nyan_orm instances.
  284. *
  285. * @return void
  286. */
  287. protected function dbInit() {
  288. $this->realmDb = new nya_realms();
  289. $this->svlanDb = new nya_qinq_svlan();
  290. $this->cvlanDb = new nya_qinq_bindings();
  291. $this->switchesqinqDb = new nya_switches_qinq();
  292. $this->switchesDb = new nya_switches();
  293. $this->switchModelsDb = new nya_switchmodels();
  294. $this->switchPortDb = new nya_switchportassign();
  295. $this->zteqinqDb = new nya_zte_qinq();
  296. $this->oltqinqDb = new nya_olt_qinq();
  297. $this->zteCardsDb = new nya_zte_cards();
  298. }
  299. /**
  300. * Load all realms
  301. *
  302. * @return void
  303. */
  304. protected function loadData() {
  305. $this->eponCards = OnuRegister::allEponCards();
  306. $this->gponCards = OnuRegister::allGponCards();
  307. $this->allRealms = $this->realmDb->getAll('id');
  308. $this->allSwitches = $this->switchesDb->getAll('id');
  309. $this->allSwitchModels = $this->switchModelsDb->getAll('id');
  310. $this->loadOccupiedCvlans();
  311. }
  312. /**
  313. * Loads system alter.ini config for further usage
  314. *
  315. * @global object $ubillingConfig
  316. *
  317. * @return void
  318. */
  319. protected function loadAlter() {
  320. global $ubillingConfig;
  321. $this->altCfg = $ubillingConfig->getAlter();
  322. }
  323. /**
  324. * Init urls
  325. *
  326. * @return void
  327. */
  328. protected function initEnv() {
  329. $this->setManagementUrl();
  330. $this->setSvlanUrl();
  331. $this->loadAlter();
  332. }
  333. /**
  334. * Set svlan url
  335. *
  336. * @return void
  337. */
  338. protected function setSvlanUrl() {
  339. $this->startSvlanUrl = self::MODULE_SVLAN . '&realm_id=' . $this->routing->get('realm_id', 'int');
  340. }
  341. /**
  342. * Set main module url.
  343. *
  344. * @return void
  345. */
  346. protected function setManagementUrl() {
  347. $this->startManagementUrl = self::MODULE . '&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_id=' . $this->svlanId;
  348. }
  349. /**
  350. * Redirects user back and show error if any
  351. *
  352. * @return void
  353. */
  354. protected function goToStartOrError($url) {
  355. if (!empty($this->error)) {
  356. $this->showError();
  357. }
  358. if (!empty($this->exceptions)) {
  359. $this->showExceptions();
  360. }
  361. //redirect on success
  362. if (empty($this->error) and empty($this->exceptions)) {
  363. rcms_redirect($url);
  364. }
  365. }
  366. /**
  367. * Validator function with subchecks.
  368. *
  369. * @return bool
  370. */
  371. protected function validateSvlan() {
  372. $this->checkSvlanRange();
  373. $this->uniqueSvlan();
  374. $this->protectedSvlan();
  375. if (!empty($this->error)) {
  376. return (false);
  377. }
  378. return (true);
  379. }
  380. /**
  381. * Check if we do not touch protected entries.
  382. *
  383. * @return bool
  384. */
  385. protected function protectedSvlan() {
  386. if ($this->notDefaultSvlanEdit()) {
  387. return (true);
  388. }
  389. if ($this->notDefaultSvlanDelete()) {
  390. return (true);
  391. }
  392. //add error if check not passed
  393. $this->error[] = __('Default SVLAN is protected and cannot be deleted or edited');
  394. return false;
  395. }
  396. /**
  397. * Check if svlan number equal to default one.
  398. *
  399. * @return bool
  400. */
  401. protected function defaultSvlanNum() {
  402. if ($this->routing->get('svlan_num', 'int') == self::DEFAULT_SVLAN) {
  403. return (true);
  404. }
  405. return (false);
  406. }
  407. /**
  408. * Check if realm id is equal to default one.
  409. *
  410. * @return bool
  411. */
  412. protected function defaultRealmId() {
  413. if ($this->routing->get('realm_id', 'int') == self::DEFAULT_REALM) {
  414. return (true);
  415. }
  416. return (false);
  417. }
  418. /**
  419. * Check if old svlan num is equal to default one.
  420. *
  421. * @return bool
  422. */
  423. protected function defaultSvlanOldNum() {
  424. if ($this->routing->get('old_svlan_num', 'int') == self::DEFAULT_SVLAN) {
  425. return (true);
  426. }
  427. return (false);
  428. }
  429. /**
  430. * Check if editing not protected entity.
  431. *
  432. * @return bool
  433. */
  434. protected function notDefaultSvlanEdit() {
  435. if (($this->routing->get('action') == 'edit')) {
  436. if ($this->defaultSvlanOldNum() and $this->defaultRealmId()) {
  437. return (false);
  438. }
  439. }
  440. return (true);
  441. }
  442. /**
  443. * Check if deleting not protected entity.
  444. *
  445. * @return bool
  446. */
  447. protected function notDefaultSvlanDelete() {
  448. if ($this->routing->get('action') == 'delete') {
  449. if ($this->defaultSvlanNum() and $this->defaultRealmId()) {
  450. return (false);
  451. }
  452. }
  453. return (true);
  454. }
  455. /**
  456. * Check if value too low.
  457. *
  458. * @return bool
  459. */
  460. protected function vlanNumTooLow($vlan) {
  461. if ($vlan < 1) {
  462. return (true);
  463. } else {
  464. return (false);
  465. }
  466. }
  467. /**
  468. * Check if value too high.
  469. *
  470. * @return bool
  471. */
  472. protected function vlanNumTooHigh($vlan) {
  473. if ($vlan > 4094) {
  474. return (true);
  475. } else {
  476. return (false);
  477. }
  478. }
  479. /**
  480. * Check if SVLAN has correct format from 0 to 4094.
  481. *
  482. * @return bool
  483. */
  484. protected function checkSvlanRange() {
  485. $svlan = $vlan = $this->routing->get('svlan_num', 'int');
  486. if (!$this->vlanNumTooLow($svlan) and!$this->vlanNumTooHigh($svlan)) {
  487. return (true);
  488. }
  489. //add error if not exited previously
  490. $this->error[] = __('Wrong value') . ': SVLAN ' . $svlan;
  491. return (false);
  492. }
  493. /**
  494. * Check if CVLAN has correct range from 0 to 4094
  495. *
  496. * @param int $cvlan
  497. *
  498. * @return bool
  499. */
  500. protected function checkCvlanRange($cvlan) {
  501. if (!$this->vlanNumTooLow($cvlan) and!$this->vlanNumTooHigh($cvlan)) {
  502. return (true);
  503. }
  504. //add error if not exited previously
  505. $this->error[] = __('Wrong value') . ': CVLAN ' . $cvlan;
  506. return (false);
  507. }
  508. /**
  509. * Check if SVLAN is unique.
  510. *
  511. * @return bool
  512. */
  513. protected function uniqueSvlan() {
  514. if ($this->uniqueSvlanAdd()) {
  515. return (true);
  516. }
  517. if ($this->uniqueSvlanEdit()) {
  518. return (true);
  519. }
  520. $this->error[] = __('Wrong value') . ': SVLAN ' . $this->routing->get('svlan_num', 'int') . ' ' . __('already exists');
  521. return (false);
  522. }
  523. /**
  524. * Check if SVLAN is unique when adding new SVLAN.
  525. *
  526. * @return bool
  527. */
  528. protected function uniqueSvlanAdd() {
  529. if ($this->routing->get('action') == 'add') {
  530. $this->svlanDb->where('realm_id', '=', $this->routing->get('realm_id', 'int'));
  531. $allSvlan = $this->svlanDb->getAll('svlan');
  532. if (isset($allSvlan[$this->routing->get('svlan_num')])) {
  533. return (false);
  534. }
  535. }
  536. return (true);
  537. }
  538. /**
  539. * Check if SVLAN is unique when editing SVLAN.
  540. *
  541. * @return bool
  542. */
  543. protected function uniqueSvlanEdit() {
  544. if ($this->routing->get('action') == 'edit') {
  545. $this->svlanDb->where('realm_id', '=', $this->routing->get('realm_id', 'int'));
  546. $this->svlanDb->where('svlan', '!=', $this->routing->get('old_svlan_num', 'int'));
  547. $allSvlan = $this->svlanDb->getAll('svlan');
  548. if (isset($allSvlan[$this->routing->get('svlan_num')])) {
  549. return (false);
  550. }
  551. }
  552. return (true);
  553. }
  554. /**
  555. * Creating new svlan
  556. *
  557. * @return void
  558. */
  559. public function addSvlan() {
  560. try {
  561. if ($this->validateSvlan()) {
  562. $this->addSvlanDb();
  563. $this->logSvlanAdd();
  564. }
  565. $this->goToStartOrError($this->startSvlanUrl);
  566. } catch (Exception $ex) {
  567. $this->exceptions[] = $ex;
  568. $this->goToStartOrError($this->startSvlanUrl);
  569. }
  570. }
  571. /**
  572. * Adding entry to DB and log.
  573. *
  574. * @return void
  575. */
  576. protected function addSvlanDb() {
  577. $this->svlanDb->data('realm_id', $this->routing->get('realm_id', 'int'));
  578. $this->svlanDb->data('svlan', $this->routing->get('svlan_num', 'int'));
  579. $this->svlanDb->data('description', $this->routing->get('description', 'mres'));
  580. $this->svlanDb->create();
  581. }
  582. /**
  583. * Editing svlan
  584. *
  585. * @return void
  586. */
  587. public function editSvlan() {
  588. try {
  589. if ($this->validateSvlan()) {
  590. $this->editSvlanDb();
  591. $this->logSvlanEdit();
  592. }
  593. $this->goToStartOrError($this->startSvlanUrl);
  594. } catch (Exception $ex) {
  595. $this->exceptions[] = $ex;
  596. $this->goToStartOrError($this->startSvlanUrl);
  597. }
  598. }
  599. /**
  600. * Saving changes to DB.
  601. *
  602. * @return void
  603. */
  604. protected function editSvlanDb() {
  605. $this->svlanDb->where('realm_id', '=', $this->routing->get('realm_id', 'int'));
  606. $this->svlanDb->where('id', '=', $this->routing->get('id', 'int'));
  607. $this->svlanDb->data('svlan', $this->routing->get('svlan_num', 'int'));
  608. $this->svlanDb->data('description', $this->routing->get('description', 'mres'));
  609. $this->svlanDb->save();
  610. }
  611. /**
  612. * Delete svlan
  613. *
  614. * @return void
  615. */
  616. public function deleteSvlan() {
  617. try {
  618. if ($this->validateSvlan()) {
  619. $this->deleteSvlanRelated();
  620. $this->logSvlanDelete();
  621. }
  622. $this->goToStartOrError($this->startSvlanUrl);
  623. } catch (Exception $ex) {
  624. $this->exceptions[] = $ex;
  625. $this->goToStartOrError($this->startSvlanUrl);
  626. }
  627. }
  628. /**
  629. * Delete all related to svlan data.
  630. *
  631. * @return void
  632. */
  633. protected function deleteSvlanRelated() {
  634. $this->deleteSvlanDb();
  635. $this->deleteSvlanSwitchesDb();
  636. $this->deleteSvlanUniversalDb();
  637. $this->deleteSvlanOltZteDb();
  638. }
  639. /**
  640. * Delete svlan from qinq_svlan table.
  641. *
  642. * @return void
  643. */
  644. protected function deleteSvlanDb() {
  645. $this->svlanDb->where('id', '=', $this->routing->get('id', 'int'));
  646. $this->svlanDb->delete();
  647. }
  648. /**
  649. * Delete svlan from switches_qinq table.
  650. *
  651. * @return void
  652. */
  653. protected function deleteSvlanSwitchesDb() {
  654. $this->switchesqinqDb->where('svlan_id', '=', $this->routing->get('id', 'int'));
  655. $this->switchesqinqDb->delete();
  656. }
  657. /**
  658. * Delete svlan from qinq_bindings table.
  659. *
  660. * @return void
  661. */
  662. protected function deleteSvlanUniversalDb() {
  663. $this->cvlanDb->where('svlan_id', '=', $this->routing->get('id', 'int'));
  664. $this->cvlanDb->delete();
  665. }
  666. /**
  667. * Delete svlan from zte_qinq table.
  668. *
  669. * @return void.
  670. */
  671. protected function deleteSvlanOltZteDb() {
  672. $this->zteqinqDb->where('svlan_id', '=', $this->routing->get('id', 'int'));
  673. $this->zteqinqDb->delete();
  674. }
  675. /**
  676. * Modal form to create new svlan.
  677. *
  678. * @return string
  679. */
  680. protected function addSvlanForm() {
  681. $addControls = wf_HiddenInput('module', 'vlanmanagement');
  682. $addControls .= wf_HiddenInput('svlan', 'true');
  683. $addControls .= wf_HiddenInput('action', 'add');
  684. $addControls .= wf_HiddenInput('realm_id', $this->routing->get('realm_id', 'int'));
  685. $addControls .= wf_TextInput('svlan_num', 'SVLAN', '', true, '');
  686. $addControls .= wf_TextInput('description', __('Description'), '', true, '', '');
  687. $addControls .= wf_Submit('Save');
  688. $form = wf_Form('', 'GET', $addControls, 'glamour');
  689. return (wf_modalAuto(web_icon_create() . ' ' . __('Create new entry'), __('Create new entry'), $form, 'ubButton'));
  690. }
  691. /**
  692. * Little hack for creating dynamic form only on demand.
  693. *
  694. * @param string $encode
  695. *
  696. * @return string
  697. */
  698. public function ajaxEditSvlan($encode) {
  699. $decode = json_decode(base64_decode($encode), true);
  700. $addControls = wf_HiddenInput('module', 'vlanmanagement');
  701. $addControls .= wf_HiddenInput('svlan', 'true');
  702. $addControls .= wf_HiddenInput('action', 'edit');
  703. $addControls .= wf_HiddenInput('id', $decode['id']);
  704. $addControls .= wf_HiddenInput('realm_id', $decode['realm_id']);
  705. $addControls .= wf_TextInput('svlan_num', 'SVLAN', $decode['svlan'], true, '');
  706. $addControls .= wf_TextInput('description', __('Description'), $decode['description'], true, '');
  707. $addControls .= wf_HiddenInput('old_svlan_num', $decode['svlan']);
  708. $addControls .= wf_Submit('Save');
  709. $form = wf_Form('', 'GET', $addControls, 'glamour');
  710. return ($form);
  711. }
  712. /**
  713. * Selector of realms for svlan submodule.
  714. *
  715. * @return string
  716. */
  717. protected function realmSvlanSelector() {
  718. if (!empty($this->allRealms)) {
  719. foreach ($this->allRealms as $id => $each) {
  720. $params[$id] = $each['realm'] . ' | ' . $each['description'];
  721. }
  722. }
  723. $inputs = wf_HiddenInput('module', 'vlanmanagement');
  724. $inputs .= wf_HiddenInput('svlan', 'true');
  725. $inputs .= wf_SelectorAC('realm_id', $params, __('Realm'), $this->routing->get('realm_id', 'int'));
  726. return (wf_Form("", "GET", $inputs));
  727. }
  728. /**
  729. * Main svlan selector.
  730. *
  731. * @param int $realmId
  732. *
  733. * @return string
  734. */
  735. public function svlanSelector($realmId) {
  736. $realmId = vf($realmId, 3);
  737. $this->svlanDb->where('realm_id', '=', $realmId);
  738. $allSvlan = $this->svlanDb->getAll('id');
  739. $allSvlanSelector[''] = self::EMPTY_SELECTOR_OPTION;
  740. if (!empty($allSvlan)) {
  741. foreach ($allSvlan as $id => $each) {
  742. $allSvlanSelector[$id] = $each['svlan'] . ' | ' . $each['description'];
  743. }
  744. }
  745. $result = wf_HiddenInput('module', 'vlanmanagement');
  746. $result .= wf_HiddenInput('realm_id', $realmId);
  747. $result .= wf_SelectorAC('svlan_id', $allSvlanSelector, 'SVLAN', $this->svlanId, true);
  748. return ($result);
  749. }
  750. /**
  751. * Link to go back from svlan submodule to main vlanmanagement module.
  752. *
  753. * @return string
  754. */
  755. protected function backSvlan() {
  756. return (wf_BackLink(self::MODULE, __('Back'), false, 'ubButton'));
  757. }
  758. /**
  759. * Render all buttons for svlan submodule.
  760. *
  761. * @return void
  762. */
  763. public function linksSvlan() {
  764. show_window('', '' .
  765. $this->backSvlan() .
  766. $this->addSvlanForm()
  767. );
  768. show_window('', $this->realmSvlanSelector());
  769. }
  770. /**
  771. * Show all available svlans.
  772. *
  773. * @return string
  774. */
  775. public function showSvlanAll() {
  776. $modal = '<link rel="stylesheet" href="./skins/vlanmanagement.css" type="text/css" media="screen" />';
  777. $modal .= wf_tag('div', false, 'cvmodal', 'id="dialog-modal_cvmodal" title="' . __('Choose') . '" style="display:none; width:1px; height:1px;"');
  778. $modal .= wf_tag('p', false, '', 'id="content-cvmodal"');
  779. $modal .= wf_tag('p', true);
  780. $modal .= wf_tag('div', true);
  781. $modal .= '<script src="./modules/jsc/vlanmanagement.js" type="text/javascript"></script>';
  782. $columns = array('ID', 'SVLAN', 'Description', 'Actions');
  783. $opts = '"order": [[ 0, "desc" ]]';
  784. $result = '';
  785. $ajaxURL = '' . self::MODULE_SVLAN . '&action=ajax&realm_id=' . $this->routing->get('realm_id', 'int');
  786. $result .= show_window('', $modal . wf_JqDtLoader($columns, $ajaxURL, false, __('Realms'), 100, $opts));
  787. return ($result);
  788. }
  789. /**
  790. * Data to render qhuery datatables.
  791. *
  792. * @return json
  793. */
  794. public function ajaxSvlanData() {
  795. $this->svlanDb->where('realm_id', '=', $this->routing->get('realm_id', 'int'));
  796. $this->allSvlan = $this->svlanDb->getAll('id');
  797. $json = new wf_JqDtHelper();
  798. if (!empty($this->allSvlan)) {
  799. foreach ($this->allSvlan as $io => $each) {
  800. $eachId = base64_encode(json_encode(array(
  801. 'id' => $each['id'],
  802. 'realm_id' => $each['realm_id'],
  803. 'svlan' => $each['svlan'],
  804. 'description' => $each['description']
  805. )));
  806. $actLinks = wf_tag('div', false, '', 'id="' . $eachId . '" onclick="svlanEdit(this)" style="display:inline-block;"') . web_edit_icon() . wf_tag('div', true);
  807. $actLinks .= wf_JSAlert(self::MODULE_SVLAN . '&action=delete&id=' . $each['id'] . '&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_num=' . $each['svlan'], web_delete_icon(), $this->messages->getDeleteAlert());
  808. $data[] = $each['id'];
  809. $data[] = $each['svlan'];
  810. $data[] = $each['description'];
  811. $data[] = $actLinks;
  812. $json->addRow($data);
  813. unset($data);
  814. }
  815. }
  816. $json->getJson();
  817. }
  818. /**
  819. * All available buttons and links on main module.
  820. *
  821. * @return void
  822. */
  823. public function linksMain() {
  824. $urls = '';
  825. if (@$this->altCfg[self::UNIVERSAL_QINQ_OPTION]) {
  826. $urls .= wf_Link(self::MODULE_UNIVERSALQINQ, web_icon_extended() . 'UniversalQINQ', false, 'ubButton');
  827. }
  828. $urls .= wf_Link(self::MODULE_SVLAN . '&realm_id=1', web_icon_extended() . 'SVLAN', false, 'ubButton');
  829. $urls .= wf_link(self::MODULE_REALMS, web_icon_extended() . __('Realms'), false, 'ubButton');
  830. $urls .= wf_Link(self::MODULE_ONU_APPLY, web_icon_extended() . __('Apply on') . ' ONU/ONT', false, 'ubButton');
  831. show_window('', $urls);
  832. show_window('', $this->realmAndSvlanSelectors());
  833. }
  834. /**
  835. * Selector for realm and svlan in main module
  836. *
  837. * @return string
  838. */
  839. public function realmAndSvlanSelectors() {
  840. $result = wf_AjaxLoader();
  841. $inputs = $this->realmMainSelector();
  842. $inputs .= wf_delimiter();
  843. $inputs2 = wf_AjaxContainer('ajcontainer', '', $this->svlanSelector($this->routing->get('realm_id', 'int') ? $this->routing->get('realm_id', 'int') : $this->defaultRealm));
  844. $inputs2 .= wf_delimiter();
  845. $result .= $inputs . wf_Form("", 'GET', $inputs2);
  846. return ($result);
  847. }
  848. /**
  849. * Creating selector for realm in main module.
  850. *
  851. * @return striing
  852. */
  853. protected function realmMainSelector() {
  854. if (!empty($this->allRealms)) {
  855. foreach ($this->allRealms as $id => $each) {
  856. $this->realmSelector[self::MODULE . '&action=realm_id_select&ajrealmid=' . $id] = $each['realm'] . ' | ' . $each['description'];
  857. }
  858. reset($this->allRealms);
  859. $this->defaultRealm = key($this->allRealms);
  860. }
  861. return (wf_AjaxSelectorAC('ajcontainer', $this->realmSelector, __('Select realm'), self::MODULE . '&action=realm_id_select&ajrealmid=' . $this->routing->get('realm_id', 'int'), false));
  862. }
  863. /**
  864. * Choose assign type switch or customer.
  865. *
  866. * @return string
  867. */
  868. protected function typeSelector() {
  869. $selector = array(self::MODULE . '&action=choosetype&type=none' => self::EMPTY_SELECTOR_OPTION);
  870. $switches = self::MODULE
  871. . '&action=choosetype&type=qinqswitches&'
  872. . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int');
  873. $universal = self::MODULE
  874. . '&action=choosetype&type=universalqinq&'
  875. . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int');
  876. $oltzte = self::MODULE
  877. . '&action=choosetype&type=qinqoltzte&'
  878. . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int');
  879. $oltnonzte = self::MODULE
  880. . '&action=choosetype&type=qinqoltnonzte&'
  881. . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int');
  882. //if qinq switches enabled
  883. if ($this->altCfg[self::QINQ_OPTION]) {
  884. $selector[$switches] = __(self::QINQ_LABEL);
  885. $this->defaultType = $switches;
  886. }
  887. if ($this->altCfg[self::QINQ_OPTION] and $this->altCfg[self::UNIVERSAL_QINQ_OPTION] and cfr(self::UNIVERSAL_QINQ_RGHT)) {
  888. $selector[$universal] = __(self::UNIVERSAL_QINQ_LABEL);
  889. }
  890. //if qinq switches disabled
  891. if (!$this->altCfg[self::QINQ_OPTION] and $this->altCfg[self::UNIVERSAL_QINQ_OPTION] and cfr(self::UNIVERSAL_QINQ_RGHT)) {
  892. $selector[$universal] = __(self::UNIVERSAL_QINQ_LABEL);
  893. $this->defaultType = $universal;
  894. } else {
  895. $this->defaultType = self::EMPTY_SELECTOR_OPTION;
  896. }
  897. if ($this->altCfg[self::UNIVERSAL_QINQ_OPTION] and $this->altCfg[self::ONUREG_QINQ_OPTION] and cfr(self::UNIVERSAL_QINQ_RGHT)) {
  898. $selector[$oltzte] = 'QINQ ' . __('pool') . ' ' . __('for') . ' ZTE OLT';
  899. $selector[$oltnonzte] = 'QINQ ' . __('pool') . ' ' . __('for') . ' OLT';
  900. }
  901. return (wf_AjaxSelectorAC('ajtypecontainer', $selector, __('Choose type'), $this->defaultType, false));
  902. }
  903. /**
  904. * Generate selector for OLTs.
  905. *
  906. * @return string
  907. */
  908. protected function oltZteSelector() {
  909. $query = 'SELECT `switches`.`id`,`switches`.`ip`,`switches`.`location`,`switchmodels`.`snmptemplate` FROM `switches` JOIN `switchmodels` ON (`switches`.`modelid` = `switchmodels`.`id`) WHERE `switches`.`desc` LIKE "%OLT%" AND `switchmodels`.`snmptemplate` LIKE "ZTE%"';
  910. $switches = simple_queryall($query);
  911. $options[self::EMPTY_SELECTOR_OPTION] = self::EMPTY_SELECTOR_OPTION;
  912. if (!empty($switches)) {
  913. foreach ($switches as $io => $each) {
  914. $options[self::MODULE . '&action=chooseoltztecard&id=' . $each['id'] . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int')] = $each['ip'] . ' ' . $each['location'];
  915. }
  916. }
  917. reset($options);
  918. $default = current($options);
  919. $result = wf_AjaxLoader();
  920. $result .= wf_AjaxSelectorAC('ajoltcontainer', $options, __('Select switch'), $default);
  921. $result .= wf_AjaxContainer('ajoltcontainer', '');
  922. return ($result);
  923. }
  924. /**
  925. * Generate selector for OLTs.
  926. *
  927. * @return string
  928. */
  929. protected function oltNonZteSelector() {
  930. $query = 'SELECT `switches`.`id`,`switches`.`ip`,`switches`.`location`,`switchmodels`.`snmptemplate` FROM `switches` JOIN `switchmodels` ON (`switches`.`modelid` = `switchmodels`.`id`) WHERE `switches`.`desc` LIKE "%OLT%" AND `switchmodels`.`snmptemplate` NOT LIKE "ZTE%"';
  931. $switches = simple_queryall($query);
  932. $options[self::EMPTY_SELECTOR_OPTION] = self::EMPTY_SELECTOR_OPTION;
  933. if (!empty($switches)) {
  934. foreach ($switches as $io => $each) {
  935. $options[self::MODULE . '&action=chooseoltnonzteport&id=' . $each['id'] . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int')] = $each['ip'] . ' ' . $each['location'];
  936. }
  937. }
  938. reset($options);
  939. $default = current($options);
  940. $result = wf_AjaxLoader();
  941. $result .= wf_AjaxSelectorAC('ajoltcontainer', $options, __('Select switch'), $default);
  942. $result .= wf_AjaxContainer('ajoltcontainer', '');
  943. return ($result);
  944. }
  945. /**
  946. * Generate card selector for choosen OLT.
  947. *
  948. * @return type
  949. */
  950. public function cardSelector() {
  951. $result = '';
  952. $options[self::EMPTY_SELECTOR_OPTION] = self::EMPTY_SELECTOR_OPTION;
  953. if ($this->routing->get('id', 'int')) {
  954. $this->zteCardsDb->selectable('`zte_cards`.`id`,`zte_cards`.`swid`,`zte_cards`.`slot_number`,`zte_cards`.`card_name`');
  955. $this->zteCardsDb->join('LEFT', 'zte_qinq', 'swid');
  956. $this->zteCardsDb->where('swid', '=', $this->routing->get('id', 'int'));
  957. $this->zteCardsDb->orderBy('slot_number', 'ASC');
  958. $allCards = $this->zteCardsDb->getAll('id');
  959. $this->zteCardsDb->selectable();
  960. if (!empty($allCards)) {
  961. foreach ($allCards as $io => $each) {
  962. $options[self::MODULE . '&action=chooseoltztecardport&id=' . $this->routing->get('id', 'int') . '&slot_number=' . $each['slot_number'] . '&card_name=' . $each['card_name'] . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int')] = $each['slot_number'] . ' | ' . $each['card_name'];
  963. }
  964. }
  965. }
  966. reset($options);
  967. $default = current($options);
  968. $result .= wf_AjaxSelectorAC('ajoltcardcontainer', $options, __('Select card'), $default);
  969. $result .= wf_AjaxContainer('ajoltcardcontainer', '');
  970. return ($result);
  971. }
  972. public function portSelector() {
  973. $form = '';
  974. $switchid = $this->routing->get('id', 'int');
  975. $modelid = $this->allSwitches[$switchid]['modelid'];
  976. $options[self::EMPTY_SELECTOR_OPTION] = self::EMPTY_SELECTOR_OPTION;
  977. $portsCount = $this->allSwitchModels[$modelid]['ports'];
  978. $maxOnuCount = 64;
  979. if ($portsCount) {
  980. $possiblePorts = range(self::ARRAY_RANGE_START, $portsCount, self::ARRAY_RANGE_STEP);
  981. $this->oltqinqDb->where('swid', '=', $switchid);
  982. $usedPortsRaw = $this->oltqinqDb->getAll('port');
  983. $usedPorts = array();
  984. foreach ($usedPortsRaw as $port => $each) {
  985. $usedPorts[] = $port;
  986. }
  987. $freePorts = array_diff($possiblePorts, $usedPorts);
  988. foreach ($freePorts as $each) {
  989. $options[$each] = $each;
  990. }
  991. }
  992. $form .= wf_HiddenInput('action', 'add');
  993. $form .= wf_HiddenInput('type', 'qinqoltnonzte');
  994. $form .= wf_HiddenInput('swid', $this->routing->get('id', 'int'));
  995. $form .= wf_Selector('port', $options, __('Select port'), self::EMPTY_SELECTOR_OPTION, true);
  996. return ($form);
  997. }
  998. /**
  999. * Generate port selector for choosen card.
  1000. *
  1001. * @return type
  1002. */
  1003. public function portCardSelector() {
  1004. $form = '';
  1005. $options[self::EMPTY_SELECTOR_OPTION] = self::EMPTY_SELECTOR_OPTION;
  1006. $portsCount = 0;
  1007. $maxOnuCount = 128;
  1008. if ($this->routing->get('id', 'int') and $this->routing->get('slot_number', 'int')) {
  1009. if (isset($this->eponCards[$this->routing->get('card_name')])) {
  1010. $portsCount = $this->eponCards[$this->routing->get('card_name')];
  1011. if ($this->routing->get('card_name') != 'ETTO' and $this->routing->get('card_name') != 'ETTOK') {
  1012. $maxOnuCount = 64;
  1013. }
  1014. } else if (isset($this->gponCards[$this->routing->get('card_name')])) {
  1015. $portsCount = $this->gponCards[$this->routing->get('card_name')];
  1016. }
  1017. }
  1018. if ($portsCount) {
  1019. $possiblePorts = range(self::ARRAY_RANGE_START, $portsCount, self::ARRAY_RANGE_STEP);
  1020. $this->zteqinqDb->where('swid', '=', $this->routing->get('id', 'int'));
  1021. $this->zteqinqDb->where('slot_number', '=', $this->routing->get('slot_number', 'int'));
  1022. $usedPortsRaw = $this->zteqinqDb->getAll('port');
  1023. $usedPorts = array();
  1024. foreach ($usedPortsRaw as $port => $each) {
  1025. $usedPorts[] = $port;
  1026. }
  1027. $freePorts = array_diff($possiblePorts, $usedPorts);
  1028. foreach ($freePorts as $each) {
  1029. $options[$each] = $each;
  1030. }
  1031. }
  1032. $form .= wf_HiddenInput('action', 'add');
  1033. $form .= wf_HiddenInput('type', 'qinqoltzte');
  1034. $form .= wf_HiddenInput('swid', $this->routing->get('id', 'int'));
  1035. $form .= wf_HiddenInput('slot_number', $this->routing->get('slot_number', 'int'));
  1036. $form .= wf_HiddenInput('card_name', $this->routing->get('card_name', 'mres'));
  1037. $form .= wf_Selector('port', $options, __('Select port'), self::EMPTY_SELECTOR_OPTION, true);
  1038. return ($form);
  1039. }
  1040. /**
  1041. * Generate selector for switches.
  1042. *
  1043. * @return string
  1044. */
  1045. protected function switchSelector() {
  1046. $options[self::EMPTY_SELECTOR_OPTION] = self::EMPTY_SELECTOR_OPTION;
  1047. $query = "SELECT `switches`.`id`,`switches`.`ip`,`switches`.`location` FROM `switches` LEFT JOIN `switches_qinq` ON `switches`.`id` = `switches_qinq`.`switchid` WHERE `switches_qinq`.`switchid` IS NULL";
  1048. $switches = simple_queryall($query);
  1049. if (!empty($switches)) {
  1050. foreach ($switches as $io => $each) {
  1051. $options[$each['id']] = $each['ip'] . ' ' . $each['location'];
  1052. }
  1053. }
  1054. return (wf_Selector('qinqswitchid', $options, __('Select switch')));
  1055. }
  1056. /**
  1057. * Generating all available types for qinq assign.
  1058. *
  1059. * @return type
  1060. */
  1061. public function types() {
  1062. $result = '';
  1063. if ($this->routing->checkGet('type')) {
  1064. switch ($this->routing->get('type')) {
  1065. case 'universalqinq':
  1066. $result .= wf_HiddenInput('type', 'universalqinq');
  1067. $result .= wf_tag('div', false) . $this->routing->get('cvlan_num', 'int') . " CVLAN" . wf_tag('div', true);
  1068. $result .= wf_TextInput('login', __('Login'), $this->routing->get('login'), true);
  1069. break;
  1070. case 'qinqswitches':
  1071. $result .= wf_HiddenInput('type', 'qinqswitches');
  1072. $result .= wf_tag('div', false) . $this->routing->get('cvlan_num', 'int') . " CVLAN" . wf_tag('div', true);
  1073. $result .= $this->switchSelector();
  1074. break;
  1075. case 'qinqoltzte':
  1076. $result .= wf_HiddenInput('type', 'qinqoltzte');
  1077. $result .= wf_tag('div', false) . $this->routing->get('cvlan_num', 'int') . " CVLAN" . wf_tag('div', true);
  1078. $result .= $this->oltZteSelector();
  1079. break;
  1080. case 'qinqoltnonzte':
  1081. $result .= wf_HiddenInput('type', 'qinqoltnonzte');
  1082. $result .= wf_tag('div', false) . $this->routing->get('cvlan_num', 'int') . " CVLAN" . wf_tag('div', true);
  1083. $result .= $this->oltNonZteSelector();
  1084. break;
  1085. }
  1086. } else {
  1087. $switches = self::MODULE
  1088. . '&action=choosetype&type=qinqswitches&'
  1089. . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int');
  1090. $universal = self::MODULE
  1091. . '&action=choosetype&type=universalqinq&'
  1092. . '&cvlan_num=' . $this->routing->get('cvlan_num', 'int');
  1093. switch ($this->defaultType) {
  1094. case $universal:
  1095. $result .= wf_HiddenInput('type', 'universalqinq');
  1096. $result .= wf_tag('div', false) . $this->routing->get('cvlan_num', 'int') . " CVLAN" . wf_tag('div', true);
  1097. $result .= wf_TextInput('login', __('Login'), $this->routing->get('login'), true);
  1098. break;
  1099. case $switches:
  1100. $result .= wf_HiddenInput('type', 'qinqswitches');
  1101. $result .= wf_tag('div', false) . $this->routing->get('cvlan_num', 'int') . " CVLAN" . wf_tag('div', true);
  1102. $result .= $this->switchSelector();
  1103. break;
  1104. }
  1105. }
  1106. return ($result);
  1107. }
  1108. /**
  1109. * Check if CVLAN not occupied by any switch.
  1110. *
  1111. * @param int $cvlan
  1112. *
  1113. * @return array or bool
  1114. */
  1115. protected function checkCvlanSwitches($cvlan) {
  1116. if (isset($this->occupiedSwitches[$cvlan])) {
  1117. $result['used'] = $this->occupiedSwitches[$cvlan];
  1118. $result['type'] = 'switch';
  1119. return ($result);
  1120. }
  1121. return (false);
  1122. }
  1123. /**
  1124. * Check if CVLAN not occupied by any customer.
  1125. *
  1126. * @param int $cvlan
  1127. *
  1128. * @return array or bool
  1129. */
  1130. protected function checkCvlanUniversal($cvlan) {
  1131. if (isset($this->occupiedUniversal[$cvlan])) {
  1132. $result['used'] = $this->occupiedUniversal[$cvlan];
  1133. $result['type'] = 'universal';
  1134. return ($result);
  1135. }
  1136. return (false);
  1137. }
  1138. /**
  1139. * Check if CVLAN not occupied by any OLT.
  1140. *
  1141. * @param int $cvlan
  1142. *
  1143. * @return array or bool
  1144. */
  1145. protected function checkCvlanOltZte($cvlan) {
  1146. if (isset($this->occupiedOltZte[$cvlan])) {
  1147. $result['used'] = $this->occupiedOltZte[$cvlan];
  1148. $result['type'] = 'oltzte';
  1149. return ($result);
  1150. }
  1151. return (false);
  1152. }
  1153. /**
  1154. * Check if CVLAN not occupied by any OLT.
  1155. *
  1156. * @param int $cvlan
  1157. *
  1158. * @return array or bool
  1159. */
  1160. protected function checkCvlanOltNonZte($cvlan) {
  1161. if (isset($this->occupiedOltNonZte[$cvlan])) {
  1162. $result['used'] = $this->occupiedOltNonZte[$cvlan];
  1163. $result['type'] = 'oltnonzte';
  1164. return ($result);
  1165. }
  1166. return (false);
  1167. }
  1168. /**
  1169. * Check if CVLAN is free.
  1170. * Multiple return is mandatory to check only in needed order.
  1171. *
  1172. * @param int $cvlan
  1173. *
  1174. * @return array
  1175. */
  1176. protected function checkCvlanFree($cvlan) {
  1177. $result['used'] = false;
  1178. $result['type'] = 'none';
  1179. if ($this->checkCvlanOltZte($cvlan)) {
  1180. $result = $this->checkCvlanOltZte($cvlan);
  1181. return ($result);
  1182. }
  1183. if ($this->checkCvlanSwitches($cvlan)) {
  1184. $result = $this->checkCvlanSwitches($cvlan);
  1185. return ($result);
  1186. }
  1187. if ($this->checkCvlanUniversal($cvlan)) {
  1188. $result = $this->checkCvlanUniversal($cvlan);
  1189. return ($result);
  1190. }
  1191. if ($this->checkCvlanOltNonZte($cvlan)) {
  1192. $result = $this->checkCvlanOltNonZte($cvlan);
  1193. return ($result);
  1194. }
  1195. return ($result);
  1196. }
  1197. /**
  1198. * Return error upon occupied CVLAN.
  1199. *
  1200. * @param array $check
  1201. * @param int $cvlan
  1202. * @param int $lastCvlan
  1203. *
  1204. * @return void
  1205. */
  1206. protected function errorOccupied($check, $cvlan, $lastCvlan) {
  1207. switch ($check['type']) {
  1208. case'switch':
  1209. $this->error[] = __('Error') . ': ' . __('trying allocate')
  1210. . ' ' . "CVLAN " . __("from") . ' ' . $this->routing->get('cvlan_num', 'int')
  1211. . ' ' . __('to') . $lastCvlan
  1212. . '. CVLAN ' . $cvlan
  1213. . ' ' . __('occcupied by switch') . ': ' . $check['used'];
  1214. break;
  1215. case 'universal':
  1216. $this->error[] = __("Error") . ': ' . __('trying allocate') . ' '
  1217. . "CVLAN " . __("from") . ' ' . $this->routing->get('cvlan_num', 'int')
  1218. . ' ' . __('to') . ' ' . $lastCvlan
  1219. . '. CVLAN ' . $cvlan . ' ' . __('occcupied by login') . ': '
  1220. . wf_link("?module=userprofile&username="
  1221. . $check['used']['login'], $check['used']['login']
  1222. );
  1223. break;
  1224. case 'olt':
  1225. $this->error[] = __('Error') . ': ' . __('trying allocate')
  1226. . ' ' . "CVLAN " . __("from") . ' ' . $this->routing->get('cvlan_num', 'int')
  1227. . ' ' . __('to') . ' ' . $lastCvlan
  1228. . '. CVLAN ' . $cvlan
  1229. . ' ' . __('occcupied by OLT') . ': ' . $check['used'];
  1230. break;
  1231. }
  1232. }
  1233. /**
  1234. * Check if we have receive correct data.
  1235. *
  1236. * @return bool
  1237. */
  1238. protected function validateNewOlt() {
  1239. if (!$this->routing->get('swid', 'int')) {
  1240. $this->error[] = __('No OLT selected');
  1241. }
  1242. if (!empty($this->error)) {
  1243. return (false);
  1244. }
  1245. return (true);
  1246. }
  1247. /**
  1248. * Add new CVLAN range binding for olt.
  1249. *
  1250. * @return void
  1251. */
  1252. protected function addNewOltZteBinding() {
  1253. try {
  1254. if ($this->validateNewOlt()) {
  1255. $maxOnuCount = 128;
  1256. $cardName = $this->routing->get('card_name');
  1257. $lastCvlan = $this->routing->get('cvlan_num', 'int') + $maxOnuCount - 1;
  1258. if (isset($this->eponCards[$cardName])) {
  1259. if ($cardName != 'ETTO' AND $cardName != 'ETTOK') {
  1260. $maxOnuCount = 64;
  1261. }
  1262. }
  1263. for ($cvlan = $this->routing->get('cvlan_num', 'int'); $cvlan <= $lastCvlan; $cvlan++) {
  1264. $check = $this->checkCvlanFree($cvlan);
  1265. if ($check['used']) {
  1266. break;
  1267. }
  1268. $checkRange = $this->checkCvlanRange($cvlan);
  1269. if (!$checkRange) {
  1270. break;
  1271. }
  1272. }
  1273. if (!$check['used'] && $checkRange) {
  1274. $this->zteqinqDb->data('swid', $this->routing->get('swid', 'int'));
  1275. $this->zteqinqDb->data('slot_number', $this->routing->get('slot_number', 'int'));
  1276. $this->zteqinqDb->data('port', $this->routing->get('port', 'int'));
  1277. $this->zteqinqDb->data('svlan_id', $this->svlanId);
  1278. $this->zteqinqDb->data('cvlan', $this->routing->get('cvlan_num', 'int'));
  1279. $this->zteqinqDb->create();
  1280. } else {
  1281. $this->errorOccupied($check, $cvlan, $lastCvlan);
  1282. }
  1283. }
  1284. } catch (Exception $ex) {
  1285. $this->exceptions[] = $ex;
  1286. }
  1287. }
  1288. /**
  1289. * Add new CVLAN range binding for olt.
  1290. *
  1291. * @return void
  1292. */
  1293. protected function addNewOltNonZteBinding() {
  1294. try {
  1295. if ($this->validateNewOlt()) {
  1296. $maxOnuCount = 64;
  1297. $lastCvlan = $this->routing->get('cvlan_num', 'int') + $maxOnuCount - 1;
  1298. for ($cvlan = $this->routing->get('cvlan_num', 'int'); $cvlan <= $lastCvlan; $cvlan++) {
  1299. $check = $this->checkCvlanFree($cvlan);
  1300. if ($check['used']) {
  1301. break;
  1302. }
  1303. $checkRange = $this->checkCvlanRange($cvlan);
  1304. if (!$checkRange) {
  1305. break;
  1306. }
  1307. }
  1308. if (!$check['used'] && $checkRange) {
  1309. $this->oltqinqDb->data('swid', $this->routing->get('swid', 'int'));
  1310. $this->oltqinqDb->data('port', $this->routing->get('port', 'int'));
  1311. $this->oltqinqDb->data('svlan_id', $this->svlanId);
  1312. $this->oltqinqDb->data('cvlan', $this->routing->get('cvlan_num', 'int'));
  1313. $this->oltqinqDb->create();
  1314. } else {
  1315. $this->errorOccupied($check, $cvlan, $lastCvlan);
  1316. }
  1317. }
  1318. } catch (Exception $ex) {
  1319. $this->exceptions[] = $ex;
  1320. }
  1321. }
  1322. /**
  1323. * Check if we have received correct data.
  1324. *
  1325. * @return bool
  1326. */
  1327. protected function validateNewSwitch() {
  1328. if (!$this->routing->get('qinqswitchid')) {
  1329. $this->error[] = __('No switch selected');
  1330. }
  1331. if ($this->routing->get('qinqswitchid') == self::EMPTY_SELECTOR_OPTION) {
  1332. $this->error[] = __('No switch selected');
  1333. }
  1334. if (!empty($this->error)) {
  1335. return (false);
  1336. }
  1337. return (true);
  1338. }
  1339. /**
  1340. * Create new switch binding
  1341. *
  1342. * @return void
  1343. */
  1344. protected function addNewSwitchBinding() {
  1345. if ($this->validateNewSwitch()) {
  1346. $modelid = $this->allSwitches[$this->routing->get('qinqswitchid', 'int')]['modelid'];
  1347. $port_number = $this->allSwitchModels[$modelid]['ports'];
  1348. $lastCvlan = $this->routing->get('cvlan_num', 'int') + $port_number - 1;
  1349. if ($this->checkCvlanRange($lastCvlan)) {
  1350. for ($cvlan = $this->routing->get('cvlan_num', 'int'); $cvlan <= $lastCvlan; $cvlan++) {
  1351. $check = $this->checkCvlanFree($cvlan);
  1352. if ($check['used']) {
  1353. break;
  1354. }
  1355. }
  1356. if (!$check['used']) {
  1357. $switchesQinQ = new SwitchesQinQ();
  1358. $qinqSaveResult = $switchesQinQ->saveQinQ();
  1359. if (!empty($qinqSaveResult)) {
  1360. $this->error[] = $qinqSaveResult;
  1361. }
  1362. } else {
  1363. $this->errorOccupied($check, $cvlan, $lastCvlan);
  1364. }
  1365. }
  1366. }
  1367. }
  1368. /**
  1369. * Create new binding based on chosen type.
  1370. *
  1371. * @return void
  1372. */
  1373. public function addNewBinding() {
  1374. try {
  1375. switch ($this->routing->get('type')) {
  1376. case 'universalqinq':
  1377. $universalqinq = new UniversalQINQ();
  1378. $result = $universalqinq->add();
  1379. if (!empty($result)) {
  1380. foreach ($result as $each) {
  1381. $this->error[] = $each;
  1382. }
  1383. }
  1384. break;
  1385. case 'qinqswitches':
  1386. $this->addNewSwitchBinding();
  1387. break;
  1388. case 'qinqoltzte':
  1389. $this->addNewOltZteBinding();
  1390. break;
  1391. case 'qinqoltnonzte':
  1392. $this->addNewOltNonZteBinding();
  1393. break;
  1394. }
  1395. $this->goToStartOrError($this->startManagementUrl);
  1396. } catch (Exception $ex) {
  1397. $this->exceptions[] = $ex;
  1398. $this->goToStartOrError($this->startManagementUrl);
  1399. }
  1400. }
  1401. /**
  1402. * Little trick with generation ajax edit form only on demand.
  1403. *
  1404. * @return string
  1405. */
  1406. public function ajaxCustomer() {
  1407. $result = '';
  1408. $this->cvlanDb->where('svlan_id', '=', $this->svlanId);
  1409. $this->cvlanDb->where('cvlan', '=', $this->routing->get('cvlan_num', 'int'));
  1410. $data = $this->cvlanDb->getAll('cvlan');
  1411. $login = $data[$this->routing->get('cvlan_num', 'int')]['login'];
  1412. $userData = zb_UserGetAllData($login);
  1413. $userData = $userData[$login];
  1414. $result .= __('Customer') . ': ';
  1415. $result .= wf_Link("?module=userprofile&username=" . $login, $userData['fulladress'] . ' ' . $userData['realname'], true);
  1416. $result .= wf_delimiter(2);
  1417. $result .= wf_Link(self::MODULE_UNIVERSALQINQ . '&action=delete&type=universal&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_id=' . $this->routing->get('svlan_id') . '&id=' . $data[$this->routing->get('cvlan_num', 'int')]['id'], web_delete_icon() . __('Delete binding'), false, 'ubButton');
  1418. return ($result);
  1419. }
  1420. /**
  1421. * Little trick with generation ajax edit form only on demand.
  1422. *
  1423. * @return string
  1424. */
  1425. public function ajaxSwitch() {
  1426. $result = '';
  1427. $this->switchesqinqDb->where('svlan_id', '=', $this->svlanId);
  1428. $this->switchesqinqDb->where('switchid', '=', $this->routing->get('switchid', 'int'));
  1429. $data = $this->switchesqinqDb->getAll('svlan_id');
  1430. $data = $data[$this->svlanId];
  1431. $switch = $this->allSwitches[$data['switchid']];
  1432. $port = $this->routing->get('cvlan_num', 'int') - $data['cvlan'] + 1;
  1433. $this->switchPortDb->where('switchid', '=', $data['switchid']);
  1434. $this->switchPortDb->where('port', '=', $port);
  1435. $swPorts = $this->switchPortDb->getAll('switchid');
  1436. $result .= __("Switch") . ': ';
  1437. $result .= wf_Link("?module=switches&edit=" . $data['switchid'], $switch['ip'] . ' ' . $switch['location']);
  1438. if (!empty($swPorts)) {
  1439. $user = $swPorts[$data['switchid']];
  1440. $userData = zb_UserGetAllData($user['login']);
  1441. $userData = $userData[$user['login']];
  1442. $result .= wf_delimiter();
  1443. $result .= __('Port') . ': ' . $port . '. CVLAN: ' . $this->routing->get('cvlan_num', 'int') . wf_delimiter() . __('Customer') . ': ' . wf_Link("?module=userprofile&username=" . $user['login'], $userData['fulladress'] . ' ' . $userData['realname'], true);
  1444. }
  1445. $result .= wf_delimiter(2);
  1446. $result .= wf_Link(self::MODULE . '&action=deleteswitchbinding&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_id=' . $this->svlanId . '&switchid=' . $data['switchid'], web_delete_icon() . __('Delete binding'), false, 'ubButton');
  1447. return ($result);
  1448. }
  1449. /**
  1450. * Little trick with generation ajax edit form only on demand.
  1451. *
  1452. * @return string
  1453. */
  1454. public function ajaxOltZte() {
  1455. $result = '';
  1456. $this->cvlanDb->where('svlan_id', '=', $this->svlanId);
  1457. $this->cvlanDb->where('cvlan', '=', $this->routing->get('cvlan_num', 'int'));
  1458. $data = $this->cvlanDb->getAll('cvlan');
  1459. if (!empty($data)) {
  1460. $login = $data[$this->routing->get('cvlan_num', 'int')]['login'];
  1461. $userData = zb_UserGetAllData($login);
  1462. $userData = $userData[$login];
  1463. $result .= __('Customer') . ': ';
  1464. $result .= wf_Link("?module=userprofile&username=" . $login, $userData['fulladress'] . ' ' . $userData['realname'], true);
  1465. $result .= wf_delimiter();
  1466. }
  1467. $result .= __("OLT") . ': ';
  1468. $result .= wf_Link("?module=ztevlanbinds&edit_card=" . $this->routing->get('switchid', 'int'), $this->occupiedOltZte[$this->routing->get('cvlan_num', 'int')]);
  1469. $result .= wf_delimiter(2);
  1470. if (!empty($data)) {
  1471. $result .= wf_Link(self::MODULE_UNIVERSALQINQ . '&action=delete&type=universal&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_id=' . $this->routing->get('svlan_id') . '&id=' . $data[$this->routing->get('cvlan_num', 'int')]['id'], web_delete_icon() . __('Delete binding') . ' ' . __('for customer'), false, 'ubButton');
  1472. }
  1473. $result .= wf_Link(self::MODULE . '&action=deleteoltztebinding&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_id=' . $this->svlanId . '&switchid=' . $this->routing->get('switchid', 'int') . '&slot_number=' . $this->occupiedOltZteSlot[$this->routing->get('cvlan_num', 'int')] . '&port=' . $this->occupiedOltZtePort[$this->routing->get('cvlan_num', 'int')], web_delete_icon() . __('Delete binding') . ' ' . __('for') . ' OLT', false, 'ubButton');
  1474. return ($result);
  1475. }
  1476. /**
  1477. * Little trick with generation ajax edit form only on demand.
  1478. *
  1479. * @return string
  1480. */
  1481. public function ajaxOltNonZte() {
  1482. $result = '';
  1483. $this->cvlanDb->where('svlan_id', '=', $this->svlanId);
  1484. $this->cvlanDb->where('cvlan', '=', $this->routing->get('cvlan_num', 'int'));
  1485. $data = $this->cvlanDb->getAll('cvlan');
  1486. if (!empty($data)) {
  1487. $login = $data[$this->routing->get('cvlan_num', 'int')]['login'];
  1488. $userData = zb_UserGetAllData($login);
  1489. $userData = $userData[$login];
  1490. $result .= __('Customer') . ': ';
  1491. $result .= wf_Link("?module=userprofile&username=" . $login, $userData['fulladress'] . ' ' . $userData['realname'], true);
  1492. $result .= wf_delimiter();
  1493. }
  1494. $result .= __("OLT") . ': ';
  1495. $result .= wf_Link("?module=switches&edit=" . $this->routing->get('switchid', 'int'), $this->occupiedOltNonZte[$this->routing->get('cvlan_num', 'int')]);
  1496. $result .= wf_delimiter(2);
  1497. if (!empty($data)) {
  1498. $result .= wf_Link(self::MODULE_UNIVERSALQINQ . '&action=delete&type=universal&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_id=' . $this->routing->get('svlan_id') . '&id=' . $data[$this->routing->get('cvlan_num', 'int')]['id'], web_delete_icon() . __('Delete binding') . ' ' . __('for customer'), false, 'ubButton');
  1499. }
  1500. $result .= wf_Link(self::MODULE . '&action=deleteoltnonztebinding&realm_id=' . $this->routing->get('realm_id', 'int') . '&svlan_id=' . $this->svlanId . '&switchid=' . $this->routing->get('switchid', 'int') . '&port=' . $this->occupiedOltNonZtePort[$this->routing->get('cvlan_num', 'int')], web_delete_icon() . __('Delete binding') . ' ' . __('for') . ' OLT', false, 'ubButton');
  1501. return ($result);
  1502. }
  1503. /**
  1504. * Delete binding for switch
  1505. *
  1506. * @return void
  1507. */
  1508. public function deleteSwitchBinding() {
  1509. try {
  1510. $this->switchesqinqDb->where('switchid', '=', $this->routing->get('switchid', 'int'));
  1511. $this->switchesqinqDb->delete();
  1512. $this->goToStartOrError($this->startManagementUrl);
  1513. } catch (Exception $ex) {
  1514. $this->exceptions[] = $ex;
  1515. $this->goToStartOrError($this->startManagementUrl);
  1516. }
  1517. }
  1518. /**
  1519. * Delete binding for olt port
  1520. *
  1521. * @return void
  1522. */
  1523. public function deleteOltZteBinding() {
  1524. try {
  1525. $this->zteqinqDb->where('swid', '=', $this->routing->get('switchid', 'int'));
  1526. $this->zteqinqDb->where('slot_number', '=', $this->routing->get('slot_number', 'int'));
  1527. $this->zteqinqDb->where('port', '=', $this->routing->get('port', 'int'));
  1528. $this->zteqinqDb->delete();
  1529. $this->goToStartOrError($this->startManagementUrl);
  1530. } catch (Exception $ex) {
  1531. $this->exceptions[] = $ex;
  1532. $this->goToStartOrError($this->startManagementUrl);
  1533. }
  1534. }
  1535. /**
  1536. * Delete binding for olt port
  1537. *
  1538. * @return void
  1539. */
  1540. public function deleteOltNonZteBinding() {
  1541. try {
  1542. $this->oltqinqDb->where('swid', '=', $this->routing->get('switchid', 'int'));
  1543. $this->oltqinqDb->where('port', '=', $this->routing->get('port', 'int'));
  1544. $this->oltqinqDb->delete();
  1545. $this->goToStartOrError($this->startManagementUrl);
  1546. } catch (Exception $ex) {
  1547. $this->exceptions[] = $ex;
  1548. $this->goToStartOrError($this->startManagementUrl);
  1549. }
  1550. }
  1551. /**
  1552. * Generate table to render qinq pair in user profile.
  1553. *
  1554. * @param string $login
  1555. *
  1556. * @return string
  1557. */
  1558. public function showUsersVlanPair($login) {
  1559. $login = mysql_real_escape_string($login);
  1560. $result = '';
  1561. $svlan = '';
  1562. $cvlan = '';
  1563. $this->cvlanDb->where('login', '=', $login);
  1564. $bind = $this->cvlanDb->getAll('login');
  1565. if (isset($bind[$login])) {
  1566. $cvlan = $bind[$login]['cvlan'];
  1567. $svlan_id = $bind[$login]['svlan_id'];
  1568. $this->svlanDb->where('id', '=', $svlan_id);
  1569. $svlans = $this->svlanDb->getAll('id');
  1570. $svlan = $svlans[$svlan_id]['svlan'];
  1571. } else {
  1572. $this->switchPortDb->where('login', '=', $login);
  1573. $switchPorts = $this->switchPortDb->getAll('login');
  1574. if (isset($switchPorts[$login])) {
  1575. $switchId = $switchPorts[$login]['switchid'];
  1576. $allSwitchQinq = $this->switchesqinqDb->getAll('switchid');
  1577. if (isset($allSwitchQinq[$switchId])) {
  1578. $port = $switchPorts[$login]['port'] - 1;
  1579. $this->switchesqinqDb->where('switchid', '=', $switchId);
  1580. $startCvlan = $allSwitchQinq[$switchId]['cvlan'];
  1581. $svlan_id = $allSwitchQinq[$switchId]['svlan_id'];
  1582. $this->svlanDb->where('id', '=', $svlan_id);
  1583. $svlans = $this->svlanDb->getAll('id');
  1584. if (isset($svlan[$svlan_id])) {
  1585. $svlan = $svlans[$svlan_id]['svlan'];
  1586. $cvlan = $startCvlan + $port;
  1587. }
  1588. }
  1589. }
  1590. }
  1591. if ($svlan !== '' and $cvlan !== '') {
  1592. $cells = wf_TableCell('SVLAN/CVLAN', '30%', 'row2');
  1593. $cells .= wf_TableCell(wf_tag('b') . $svlan . '/' . $cvlan . wf_tag('b', true));
  1594. $rows = wf_TableRow($cells, 'row3');
  1595. $result .= wf_TableBody($rows, '100%', '0');
  1596. }
  1597. return ($result);
  1598. }
  1599. /**
  1600. * generate form for new binding.
  1601. *
  1602. * @return stinrg
  1603. */
  1604. public function ajaxChooseForm() {
  1605. $inputs = wf_HiddenInput('module', 'vlanmanagement');
  1606. $inputs .= wf_HiddenInput('action', 'add');
  1607. $inputs .= wf_HiddenInput('realm_id', $this->routing->get('realm_id', 'int'));
  1608. $inputs .= wf_HiddenInput('svlan_id', $this->svlanId);
  1609. $inputs .= wf_HiddenInput('cvlan_num', $this->routing->get('cvlan_num', 'int'));
  1610. $inputs .= wf_AjaxLoader();
  1611. $inputs2 = $this->typeSelector() . wf_delimiter(1);
  1612. $inputs .= wf_AjaxContainer('ajtypecontainer', '', $this->types($this->defaultType));
  1613. $inputs .= wf_Submit(__('Save'));
  1614. $form = $inputs2 . wf_Form('', "GET", $inputs, 'glamour');
  1615. return ($form);
  1616. }
  1617. /**
  1618. * Load all occcupied cvlans by customers and equipment
  1619. *
  1620. * @return void
  1621. */
  1622. protected function loadOccupiedCvlans() {
  1623. $this->loadUniversalCvlans();
  1624. $this->loadOccupiedPorts();
  1625. $this->loadSwitchesCvlans();
  1626. if ($this->altCfg[self::ONUREG_QINQ_OPTION]) {
  1627. $this->loadOltsZteCvlans();
  1628. $this->loadOltsNonZteCvlans();
  1629. }
  1630. }
  1631. /**
  1632. * Contains all cvlans occupied by customers.
  1633. *
  1634. * @return void
  1635. */
  1636. protected function loadUniversalCvlans() {
  1637. try {
  1638. $this->cvlanDb->where('svlan_id', '=', $this->svlanId);
  1639. $this->occupiedUniversal = $this->cvlanDb->getAll('cvlan');
  1640. } catch (Exception $ex) {
  1641. $this->exceptions[] = $ex;
  1642. }
  1643. }
  1644. /**
  1645. * Contains all cvlans occupied by switches.
  1646. *
  1647. * @return void
  1648. */
  1649. protected function loadSwitchesCvlans() {
  1650. try {
  1651. $this->switchesqinqDb->where('svlan_id', '=', $this->svlanId);
  1652. foreach ($this->switchesqinqDb->getAll('switchid') as $io => $each) {
  1653. $portCounter = 1;
  1654. if (isset($this->allSwitches[$each['switchid']])) {
  1655. $modelid = $this->allSwitches[$each['switchid']]['modelid'];
  1656. $portNumber = $this->allSwitchModels[$modelid]['ports'];
  1657. for ($i = $each['cvlan']; $i <= ($each['cvlan'] + $portNumber - 1); $i++) {
  1658. $this->occupiedSwitches[$i] = $this->allSwitches[$each['switchid']]['ip'] . ' | ' . $this->allSwitches[$each['switchid']]['location'];
  1659. $this->switchVlans[$i] = $each['switchid'];
  1660. if (isset($this->allPorts[$each['switchid']])) {
  1661. $curPorts = $this->allPorts[$each['switchid']];
  1662. foreach ($curPorts as $eachPort => $eachLogin) {
  1663. if ($eachPort == $portCounter) {
  1664. $this->switchPortCustomer[$i] = array('port' => $eachPort, 'login' => $eachLogin);
  1665. }
  1666. }
  1667. }
  1668. $this->switchPortFree[$i] = $portCounter;
  1669. $portCounter++;
  1670. }
  1671. }
  1672. }
  1673. } catch (Exception $ex) {
  1674. $this->exceptions[] = $ex;
  1675. }
  1676. }
  1677. /**
  1678. * Contains all cvlans occupied by olt.
  1679. *
  1680. * @return void
  1681. */
  1682. protected function loadOltsZteCvlans() {
  1683. try {
  1684. $this->zteqinqDb->join('RIGHT', 'zte_cards', 'swid,slot_number');
  1685. $this->zteqinqDb->selectable('`zte_qinq`.`id`,`zte_cards`.`swid`,`zte_cards`.`slot_number`,`zte_cards`.`card_name`,`zte_qinq`.`port`,`zte_qinq`.`cvlan`');
  1686. $this->zteqinqDb->where('zte_qinq.port', 'IS NOT', 'NULL');
  1687. $this->zteqinqDb->where('zte_qinq.svlan_id', '=', $this->svlanId);
  1688. $allZteBinding = $this->zteqinqDb->getAll('id');
  1689. $this->zteqinqDb->selectable();
  1690. if (!empty($allZteBinding)) {
  1691. foreach ($allZteBinding as $io => $each) {
  1692. $maxOnuCount = 128;
  1693. if (isset($this->eponCards[$each['card_name']])) {
  1694. if ($each['card_name'] != 'ETTO' AND $each['card_name'] != 'ETTOK') {
  1695. $maxOnuCount = 64;
  1696. }
  1697. }
  1698. for ($cvlan = $each['cvlan']; $cvlan <= $each['cvlan'] + $maxOnuCount - 1; $cvlan++) {
  1699. $currentOlt = $this->allSwitches[$each['swid']];
  1700. $this->occupiedOltZte[$cvlan] = $currentOlt['ip'] . ' ' . $currentOlt['location'] . ' (' . __('Slot') . ': ' . $each['slot_number'] . '/' . $each['card_name'] . ' ' . __('Port') . ': ' . $each['port'] . ')';
  1701. $this->occupiedOltZteSlot[$cvlan] = $each['slot_number'];
  1702. $this->occupiedOltZtePort[$cvlan] = $each['port'];
  1703. $this->occupiedOltZteId[$cvlan] = $each['swid'];
  1704. }
  1705. }
  1706. }
  1707. } catch (Exception $ex) {
  1708. $this->exceptions[] = $ex;
  1709. }
  1710. }
  1711. /**
  1712. * Contains all cvlans occupied by olt.
  1713. *
  1714. * @return void
  1715. */
  1716. protected function loadOltsNonZteCvlans() {
  1717. try {
  1718. $this->oltqinqDb->where('svlan_id', '=', $this->svlanId);
  1719. $allOltBinding = $this->oltqinqDb->getAll('id');
  1720. $this->zteqinqDb->selectable();
  1721. if (!empty($allOltBinding)) {
  1722. foreach ($allOltBinding as $io => $each) {
  1723. $maxOnuCount = 64;
  1724. for ($cvlan = $each['cvlan']; $cvlan <= $each['cvlan'] + $maxOnuCount - 1; $cvlan++) {
  1725. $currentOlt = $this->allSwitches[$each['swid']];
  1726. $this->occupiedOltNonZte[$cvlan] = $currentOlt['ip'] . ' ' . $currentOlt['location'] . ' (' . __('Port') . ': ' . $each['port'] . ')';
  1727. $this->occupiedOltNonZtePort[$cvlan] = $each['port'];
  1728. $this->occupiedOltNonZteId[$cvlan] = $each['swid'];
  1729. }
  1730. }
  1731. }
  1732. } catch (Exception $ex) {
  1733. $this->exceptions[] = $ex;
  1734. }
  1735. }
  1736. /**
  1737. * Load all switchports
  1738. *
  1739. * @return void
  1740. */
  1741. protected function loadOccupiedPorts() {
  1742. $allPortsRaw = $this->switchPortDb->getAll('id');
  1743. if (!empty($allPortsRaw)) {
  1744. foreach ($allPortsRaw as $io => $each) {
  1745. $this->allPorts[$each['switchid']][$each['port']] = $each['login'];
  1746. }
  1747. }
  1748. }
  1749. /**
  1750. * Adding html properties based on type.
  1751. *
  1752. * @param int $cvlan
  1753. *
  1754. * @return array
  1755. */
  1756. protected function setMatricContainerColor($cvlan) {
  1757. $switchid = '';
  1758. $check = $this->checkCvlanFree($cvlan);
  1759. if ($check['type'] == 'oltzte') {
  1760. if (isset($this->occupiedUniversal[$cvlan])) {
  1761. $color = 'occupied_zte_olt_with_customer';
  1762. } else {
  1763. $color = 'occupied_zte_olt';
  1764. }
  1765. $switchid = $this->occupiedOltZteId[$cvlan];
  1766. } elseif ($check['type'] == 'oltnonzte') {
  1767. if (isset($this->occupiedUniversal[$cvlan])) {
  1768. $color = 'occupied_nonzte_olt_with_customer';
  1769. } else {
  1770. $color = 'occupied_nonzte_olt';
  1771. }
  1772. $switchid = $this->occupiedOltNonZteId[$cvlan];
  1773. } elseif ($check['type'] == 'switch') {
  1774. if (isset($this->switchPortCustomer[$cvlan])) {
  1775. $color = 'occupied_switch_with_customer';
  1776. } else {
  1777. $color = 'occupied_switch';
  1778. }
  1779. if (isset($this->switchVlans[$cvlan])) {
  1780. $switchid = $this->switchVlans[$cvlan];
  1781. }
  1782. } elseif ($check['type'] == 'universal') {
  1783. $color = 'occupied_customer';
  1784. } else {
  1785. $color = 'free_vlan';
  1786. }
  1787. $onclick = $this->setMatrixOnlick($color);
  1788. $result['switchid'] = $switchid;
  1789. $result['color'] = $color;
  1790. $result['onclick'] = $onclick;
  1791. return ($result);
  1792. }
  1793. /**
  1794. * Set onclick property based on class.
  1795. *
  1796. * @param string $color
  1797. *
  1798. * @return string
  1799. */
  1800. protected function setMatrixOnlick($color) {
  1801. $onclick = '';
  1802. switch ($color) {
  1803. case 'free_vlan':
  1804. $onclick = 'onclick = "vlanAcquire(this)"';
  1805. break;
  1806. case 'occupied_customer':
  1807. $onclick = 'onclick = "occupiedByCustomer(this)"';
  1808. break;
  1809. case 'occupied_zte_olt_with_customer':
  1810. case 'occupied_zte_olt':
  1811. $onclick = 'onclick = "occupiedByOltZte(this)"';
  1812. break;
  1813. case 'occupied_nonzte_olt_with_customer':
  1814. case 'occupied_nonzte_olt':
  1815. $onclick = 'onclick = "occupiedByOltNonZte(this)"';
  1816. break;
  1817. case 'occupied_switch_with_customer':
  1818. case 'occupied_switch':
  1819. $onclick = 'onclick = "occupiedBySwitch(this)"';
  1820. break;
  1821. }
  1822. return ($onclick);
  1823. }
  1824. /**
  1825. * Render main cvlan matrix.
  1826. *
  1827. * @return void
  1828. */
  1829. public function cvlanMatrix() {
  1830. $result = '';
  1831. if ($this->routing->checkGet(array('realm_id', 'svlan_id'))) {
  1832. $result .= $this->createMatrixMainContainer();
  1833. for ($cvlan = 1; $cvlan <= 4094; $cvlan++) {
  1834. $result .= $this->createMatrixDataContainer($cvlan);
  1835. }
  1836. $result .= $this->loadMatrixJs();
  1837. }
  1838. show_window('', $result);
  1839. }
  1840. /**
  1841. * Create main container and load stylesheets.
  1842. *
  1843. * @return string
  1844. */
  1845. protected function createMatrixMainContainer() {
  1846. $result = '<link rel="stylesheet" href="./skins/vlanmanagement.css" type="text/css" media="screen" />';
  1847. $result .= wf_tag('div', false, 'cvmodal', 'id = "dialog-modal_cvmodal" title = "' . __('Choose') . '" style = "display:none; width:1px; height:1px;"');
  1848. $result .= wf_tag('p', false, '', 'id = "content-cvmodal"');
  1849. $result .= wf_tag('p', true);
  1850. $result .= wf_tag('div', true);
  1851. return ($result);
  1852. }
  1853. /**
  1854. * Generate div container with data for cvlan.
  1855. *
  1856. * @param int $cvlan
  1857. *
  1858. * @return string
  1859. */
  1860. protected function createMatrixDataContainer($cvlan) {
  1861. $matrixColorData = $this->setMatricContainerColor($cvlan);
  1862. $result = wf_tag('div', false, 'cvlanMatrixContainer ' . $matrixColorData['color'], 'id = "container_' . $this->routing->get('realm_id', 'int') .
  1863. '/' . $this->svlanId .
  1864. '/' . $cvlan . '/' . $matrixColorData['switchid'] . '" ' . $matrixColorData['onclick'] . '');
  1865. $result .= $cvlan;
  1866. $result .= $this->createMatrixPortCaption($cvlan);
  1867. $result .= wf_tag('div', true);
  1868. return ($result);
  1869. }
  1870. /**
  1871. * Add div with port caption if exists.
  1872. *
  1873. * @param int $cvlan
  1874. *
  1875. * @return string
  1876. */
  1877. protected function createMatrixPortCaption($cvlan) {
  1878. $result = '';
  1879. if (isset($this->switchPortCustomer[$cvlan])) {
  1880. $result = wf_tag('div', false, 'port_caption') . $this->switchPortCustomer[$cvlan]['port'] . wf_tag('div', true);
  1881. } elseif (isset($this->switchPortFree[$cvlan])) {
  1882. $result = wf_tag('div', false, 'port_caption') . $this->switchPortFree[$cvlan] . wf_tag('div', true);
  1883. }
  1884. return ($result);
  1885. }
  1886. /**
  1887. * Returns html string to load JS file.
  1888. *
  1889. * @return string
  1890. */
  1891. protected function loadMatrixJs() {
  1892. $result = '<script src = "./modules/jsc/vlanmanagement.js" type = "text/javascript"></script>';
  1893. return ($result);
  1894. }
  1895. /**
  1896. * Get all svlan by id as primary key
  1897. *
  1898. * @return array
  1899. */
  1900. public function getAllSvlan() {
  1901. return ($this->svlanDb->getAll('id'));
  1902. }
  1903. /**
  1904. * Get all realms with id as primary key
  1905. *
  1906. * @return array
  1907. */
  1908. public function getAllRealms() {
  1909. return ($this->allRealms);
  1910. }
  1911. /**
  1912. * Generate ajax list of OLTs.
  1913. *
  1914. * @return string
  1915. */
  1916. public function oltListAjaxRender() {
  1917. $add = '';
  1918. $json = new wf_JqDtHelper();
  1919. $query = 'SELECT `switches`.`id`,`switches`.`ip`,`switches`.`location`,`switchmodels`.`snmptemplate`,`switchmodels`.`modelname` FROM `switches` JOIN `switchmodels` ON (`switches`.`modelid` = `switchmodels`.`id`) WHERE `switches`.`desc` LIKE "%OLT%" AND `switchmodels`.`snmptemplate` NOT LIKE "ZTE%"';
  1920. $olts = simple_queryall($query);
  1921. if ($this->routing->checkGet('username')) {
  1922. $add .= "&username=" . $this->routing->get('username', 'mres');
  1923. }
  1924. if (!empty($olts)) {
  1925. foreach ($olts as $io => $each) {
  1926. $data[] = trim($each['id']);
  1927. $data[] = trim($each['ip']);
  1928. $data[] = trim($each['location']);
  1929. $data[] = trim($each['modelname']);
  1930. $vlancontrols = wf_Link(self::MODULE_ONU_APPLY . "&oltid=" . $each['id'] . $add, wf_img('skins/snmp.png'));
  1931. $data[] = $vlancontrols;
  1932. $json->addRow($data);
  1933. unset($data);
  1934. }
  1935. }
  1936. /*
  1937. $countersSummary = wf_tag('br');
  1938. $countersSummary .= wf_tag('br') . wf_tag('b') . __('Total') . ': ' . $countTotal . wf_tag('b', true) . wf_tag('br');
  1939. *
  1940. */
  1941. $json->getJson();
  1942. }
  1943. /**
  1944. * JQDT container for olt selections
  1945. *
  1946. * @return string
  1947. */
  1948. public function oltListShow() {
  1949. $result = '';
  1950. $add = '';
  1951. $columns = array('ID', 'IP', 'Location', 'Model', 'Actions');
  1952. $opts = '"order": [[ 0, "asc" ]]';
  1953. if ($this->routing->checkGet('username')) {
  1954. $add .= "&username=" . $this->routing->get('username', 'mres');
  1955. }
  1956. $result .= wf_JqDtLoader($columns, self::MODULE_ONU_APPLY_AJAXOLTLIST . $add, false, __('Request'), 100, $opts);
  1957. return($result);
  1958. }
  1959. /**
  1960. * Create main container and load stylesheets.
  1961. *
  1962. * @return string
  1963. */
  1964. public function vlanChangeModal() {
  1965. $result = '<link rel="stylesheet" href="./skins/vlanmanagement.css" type="text/css" media="screen" />';
  1966. $result .= wf_tag('div', false, 'cvmodal', 'id = "dialog-modal_cvmodal" title = "' . __('Choose') . '" style = "display:none; width:1px; height:1px;"');
  1967. $result .= wf_tag('p', false, '', 'id = "content-cvmodal"');
  1968. $result .= wf_tag('p', true);
  1969. $result .= wf_tag('div', true);
  1970. return ($result);
  1971. }
  1972. /**
  1973. * If we have any errors show all of them
  1974. *
  1975. * @return void
  1976. */
  1977. protected function showError() {
  1978. foreach ($this->error as $io => $each) {
  1979. show_error($each);
  1980. }
  1981. }
  1982. /**
  1983. * Show exceptions if any.
  1984. *
  1985. * @return void
  1986. */
  1987. protected function showExceptions() {
  1988. foreach ($this->exceptions as $io => $each) {
  1989. show_error($each);
  1990. }
  1991. }
  1992. /**
  1993. * Log add action
  1994. *
  1995. * @return void
  1996. */
  1997. protected function logSvlanAdd() {
  1998. log_register('CREATE SVLAN (' . trim($this->routing->get('svlan_num', 'int')) . ')');
  1999. }
  2000. /**
  2001. * Log delete action
  2002. *
  2003. * @return void
  2004. */
  2005. protected function logSvlanDelete() {
  2006. log_register('DELETE SVLAN (' . trim($this->routing->get('svlan_num', 'int')) . ')');
  2007. }
  2008. /**
  2009. * Log edit action
  2010. *
  2011. * @return void
  2012. */
  2013. protected function logSvlanEdit() {
  2014. log_register('EDIT SVLAN (' . trim($this->routing->get('old_svlan_num', 'int')) . ') ' . 'ON (' . trim($this->routing->get('svlan_num', 'int')) . ')');
  2015. }
  2016. /**
  2017. * Log add action
  2018. *
  2019. * @return void
  2020. */
  2021. protected function logAdd() {
  2022. log_register('CREATE realm (' . trim($this->routing->get('realm', 'mres')) . ')');
  2023. }
  2024. /**
  2025. * Log delete action
  2026. *
  2027. * @return void
  2028. */
  2029. protected function logDelete() {
  2030. log_register('DELETE realm (' . trim($this->routing->get('realm', 'mres')) . ')');
  2031. }
  2032. /**
  2033. * Log edit action
  2034. *
  2035. * @return void
  2036. */
  2037. protected function logEdit() {
  2038. log_register('EDIT realm (' . trim($this->routing->get('old_realm', 'mres')) . ') ' . 'ON (' . trim($this->routing->get('realm', 'mres')) . ')');
  2039. }
  2040. }