PageRenderTime 51ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/plugins/sfPhpExcelPlugin/lib/PHPExcel/PHPExcel/Worksheet/Protection.php

https://github.com/dziamid/Marcel
PHP | 533 lines | 175 code | 57 blank | 301 comment | 3 complexity | 48342efaf5103342f17e21de77d4a4f6 MD5 | raw file
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2009 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Worksheet
  23. * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** PHPExcel_Shared_PasswordHasher */
  28. require_once 'PHPExcel/Shared/PasswordHasher.php';
  29. /**
  30. * PHPExcel_Worksheet_Protection
  31. *
  32. * @category PHPExcel
  33. * @package PHPExcel_Worksheet
  34. * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  35. */
  36. class PHPExcel_Worksheet_Protection
  37. {
  38. /**
  39. * Sheet
  40. *
  41. * @var boolean
  42. */
  43. private $_sheet;
  44. /**
  45. * Objects
  46. *
  47. * @var boolean
  48. */
  49. private $_objects;
  50. /**
  51. * Scenarios
  52. *
  53. * @var boolean
  54. */
  55. private $_scenarios;
  56. /**
  57. * Format cells
  58. *
  59. * @var boolean
  60. */
  61. private $_formatCells;
  62. /**
  63. * Format columns
  64. *
  65. * @var boolean
  66. */
  67. private $_formatColumns;
  68. /**
  69. * Format rows
  70. *
  71. * @var boolean
  72. */
  73. private $_formatRows;
  74. /**
  75. * Insert columns
  76. *
  77. * @var boolean
  78. */
  79. private $_insertColumns;
  80. /**
  81. * Insert rows
  82. *
  83. * @var boolean
  84. */
  85. private $_insertRows;
  86. /**
  87. * Insert hyperlinks
  88. *
  89. * @var boolean
  90. */
  91. private $_insertHyperlinks;
  92. /**
  93. * Delete columns
  94. *
  95. * @var boolean
  96. */
  97. private $_deleteColumns;
  98. /**
  99. * Delete rows
  100. *
  101. * @var boolean
  102. */
  103. private $_deleteRows;
  104. /**
  105. * Select locked cells
  106. *
  107. * @var boolean
  108. */
  109. private $_selectLockedCells;
  110. /**
  111. * Sort
  112. *
  113. * @var boolean
  114. */
  115. private $_sort;
  116. /**
  117. * AutoFilter
  118. *
  119. * @var boolean
  120. */
  121. private $_autoFilter;
  122. /**
  123. * Pivot tables
  124. *
  125. * @var boolean
  126. */
  127. private $_pivotTables;
  128. /**
  129. * Select unlocked cells
  130. *
  131. * @var boolean
  132. */
  133. private $_selectUnlockedCells;
  134. /**
  135. * Password
  136. *
  137. * @var string
  138. */
  139. private $_password;
  140. /**
  141. * Create a new PHPExcel_Worksheet_Protection
  142. */
  143. public function __construct()
  144. {
  145. // Initialise values
  146. $this->_sheet = false;
  147. $this->_objects = false;
  148. $this->_scenarios = false;
  149. $this->_formatCells = false;
  150. $this->_formatColumns = false;
  151. $this->_formatRows = false;
  152. $this->_insertColumns = false;
  153. $this->_insertRows = false;
  154. $this->_insertHyperlinks = false;
  155. $this->_deleteColumns = false;
  156. $this->_deleteRows = false;
  157. $this->_selectLockedCells = false;
  158. $this->_sort = false;
  159. $this->_autoFilter = false;
  160. $this->_pivotTables = false;
  161. $this->_selectUnlockedCells = false;
  162. $this->_password = '';
  163. }
  164. /**
  165. * Is some sort of protection enabled?
  166. *
  167. * @return boolean
  168. */
  169. function isProtectionEnabled() {
  170. return $this->_sheet ||
  171. $this->_objects ||
  172. $this->_scenarios ||
  173. $this->_formatCells ||
  174. $this->_formatColumns ||
  175. $this->_formatRows ||
  176. $this->_insertColumns ||
  177. $this->_insertRows ||
  178. $this->_insertHyperlinks ||
  179. $this->_deleteColumns ||
  180. $this->_deleteRows ||
  181. $this->_selectLockedCells ||
  182. $this->_sort ||
  183. $this->_autoFilter ||
  184. $this->_pivotTables ||
  185. $this->_selectUnlockedCells;
  186. }
  187. /**
  188. * Get Sheet
  189. *
  190. * @return boolean
  191. */
  192. function getSheet() {
  193. return $this->_sheet;
  194. }
  195. /**
  196. * Set Sheet
  197. *
  198. * @param boolean $pValue
  199. */
  200. function setSheet($pValue = false) {
  201. $this->_sheet = $pValue;
  202. }
  203. /**
  204. * Get Objects
  205. *
  206. * @return boolean
  207. */
  208. function getObjects() {
  209. return $this->_objects;
  210. }
  211. /**
  212. * Set Objects
  213. *
  214. * @param boolean $pValue
  215. */
  216. function setObjects($pValue = false) {
  217. $this->_objects = $pValue;
  218. }
  219. /**
  220. * Get Scenarios
  221. *
  222. * @return boolean
  223. */
  224. function getScenarios() {
  225. return $this->_scenarios;
  226. }
  227. /**
  228. * Set Scenarios
  229. *
  230. * @param boolean $pValue
  231. */
  232. function setScenarios($pValue = false) {
  233. $this->_scenarios = $pValue;
  234. }
  235. /**
  236. * Get FormatCells
  237. *
  238. * @return boolean
  239. */
  240. function getFormatCells() {
  241. return $this->_formatCells;
  242. }
  243. /**
  244. * Set FormatCells
  245. *
  246. * @param boolean $pValue
  247. */
  248. function setFormatCells($pValue = false) {
  249. $this->_formatCells = $pValue;
  250. }
  251. /**
  252. * Get FormatColumns
  253. *
  254. * @return boolean
  255. */
  256. function getFormatColumns() {
  257. return $this->_formatColumns;
  258. }
  259. /**
  260. * Set FormatColumns
  261. *
  262. * @param boolean $pValue
  263. */
  264. function setFormatColumns($pValue = false) {
  265. $this->_formatColumns = $pValue;
  266. }
  267. /**
  268. * Get FormatRows
  269. *
  270. * @return boolean
  271. */
  272. function getFormatRows() {
  273. return $this->_formatRows;
  274. }
  275. /**
  276. * Set FormatRows
  277. *
  278. * @param boolean $pValue
  279. */
  280. function setFormatRows($pValue = false) {
  281. $this->_formatRows = $pValue;
  282. }
  283. /**
  284. * Get InsertColumns
  285. *
  286. * @return boolean
  287. */
  288. function getInsertColumns() {
  289. return $this->_insertColumns;
  290. }
  291. /**
  292. * Set InsertColumns
  293. *
  294. * @param boolean $pValue
  295. */
  296. function setInsertColumns($pValue = false) {
  297. $this->_insertColumns = $pValue;
  298. }
  299. /**
  300. * Get InsertRows
  301. *
  302. * @return boolean
  303. */
  304. function getInsertRows() {
  305. return $this->_insertRows;
  306. }
  307. /**
  308. * Set InsertRows
  309. *
  310. * @param boolean $pValue
  311. */
  312. function setInsertRows($pValue = false) {
  313. $this->_insertRows = $pValue;
  314. }
  315. /**
  316. * Get InsertHyperlinks
  317. *
  318. * @return boolean
  319. */
  320. function getInsertHyperlinks() {
  321. return $this->_insertHyperlinks;
  322. }
  323. /**
  324. * Set InsertHyperlinks
  325. *
  326. * @param boolean $pValue
  327. */
  328. function setInsertHyperlinks($pValue = false) {
  329. $this->_insertHyperlinks = $pValue;
  330. }
  331. /**
  332. * Get DeleteColumns
  333. *
  334. * @return boolean
  335. */
  336. function getDeleteColumns() {
  337. return $this->_deleteColumns;
  338. }
  339. /**
  340. * Set DeleteColumns
  341. *
  342. * @param boolean $pValue
  343. */
  344. function setDeleteColumns($pValue = false) {
  345. $this->_deleteColumns = $pValue;
  346. }
  347. /**
  348. * Get DeleteRows
  349. *
  350. * @return boolean
  351. */
  352. function getDeleteRows() {
  353. return $this->_deleteRows;
  354. }
  355. /**
  356. * Set DeleteRows
  357. *
  358. * @param boolean $pValue
  359. */
  360. function setDeleteRows($pValue = false) {
  361. $this->_deleteRows = $pValue;
  362. }
  363. /**
  364. * Get SelectLockedCells
  365. *
  366. * @return boolean
  367. */
  368. function getSelectLockedCells() {
  369. return $this->_selectLockedCells;
  370. }
  371. /**
  372. * Set SelectLockedCells
  373. *
  374. * @param boolean $pValue
  375. */
  376. function setSelectLockedCells($pValue = false) {
  377. $this->_selectLockedCells = $pValue;
  378. }
  379. /**
  380. * Get Sort
  381. *
  382. * @return boolean
  383. */
  384. function getSort() {
  385. return $this->_sort;
  386. }
  387. /**
  388. * Set Sort
  389. *
  390. * @param boolean $pValue
  391. */
  392. function setSort($pValue = false) {
  393. $this->_sort = $pValue;
  394. }
  395. /**
  396. * Get AutoFilter
  397. *
  398. * @return boolean
  399. */
  400. function getAutoFilter() {
  401. return $this->_autoFilter;
  402. }
  403. /**
  404. * Set AutoFilter
  405. *
  406. * @param boolean $pValue
  407. */
  408. function setAutoFilter($pValue = false) {
  409. $this->_autoFilter = $pValue;
  410. }
  411. /**
  412. * Get PivotTables
  413. *
  414. * @return boolean
  415. */
  416. function getPivotTables() {
  417. return $this->_pivotTables;
  418. }
  419. /**
  420. * Set PivotTables
  421. *
  422. * @param boolean $pValue
  423. */
  424. function setPivotTables($pValue = false) {
  425. $this->_pivotTables = $pValue;
  426. }
  427. /**
  428. * Get SelectUnlockedCells
  429. *
  430. * @return boolean
  431. */
  432. function getSelectUnlockedCells() {
  433. return $this->_selectUnlockedCells;
  434. }
  435. /**
  436. * Set SelectUnlockedCells
  437. *
  438. * @param boolean $pValue
  439. */
  440. function setSelectUnlockedCells($pValue = false) {
  441. $this->_selectUnlockedCells = $pValue;
  442. }
  443. /**
  444. * Get Password (hashed)
  445. *
  446. * @return string
  447. */
  448. function getPassword() {
  449. return $this->_password;
  450. }
  451. /**
  452. * Set Password
  453. *
  454. * @param string $pValue
  455. * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true
  456. */
  457. function setPassword($pValue = '', $pAlreadyHashed = false) {
  458. if (!$pAlreadyHashed) {
  459. $pValue = PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
  460. }
  461. $this->_password = $pValue;
  462. }
  463. /**
  464. * Implement PHP __clone to create a deep clone, not just a shallow copy.
  465. */
  466. public function __clone() {
  467. $vars = get_object_vars($this);
  468. foreach ($vars as $key => $value) {
  469. if (is_object($value)) {
  470. $this->$key = clone $value;
  471. } else {
  472. $this->$key = $value;
  473. }
  474. }
  475. }
  476. }