PHPExcel_Worksheet
[ class tree: PHPExcel_Worksheet ] [ index: PHPExcel_Worksheet ] [ all elements ]

Source for file Protection.php

Documentation is available at Protection.php

  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    1.7.0, 2009-08-10
  26.  */
  27.  
  28.  
  29. /** PHPExcel root directory */
  30. if (!defined('PHPEXCEL_ROOT')) {
  31.     /**
  32.      * @ignore
  33.      */
  34.     define('PHPEXCEL_ROOT'dirname(__FILE__'/../../');
  35. }
  36.  
  37. /** PHPExcel_Shared_PasswordHasher */
  38. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/PasswordHasher.php';
  39.  
  40.  
  41. /**
  42.  * PHPExcel_Worksheet_Protection
  43.  *
  44.  * @category   PHPExcel
  45.  * @package    PHPExcel_Worksheet
  46.  * @copyright  Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
  47.  */
  48. {
  49.     /**
  50.      * Sheet
  51.      *
  52.      * @var boolean 
  53.      */
  54.     private $_sheet;
  55.     
  56.     /**
  57.      * Objects
  58.      *
  59.      * @var boolean 
  60.      */
  61.     private $_objects;
  62.     
  63.     /**
  64.      * Scenarios
  65.      *
  66.      * @var boolean 
  67.      */
  68.     private $_scenarios;
  69.     
  70.     /**
  71.      * Format cells
  72.      *
  73.      * @var boolean 
  74.      */
  75.     private $_formatCells;
  76.     
  77.     /**
  78.      * Format columns
  79.      *
  80.      * @var boolean 
  81.      */
  82.     private $_formatColumns;
  83.     
  84.     /**
  85.      * Format rows
  86.      *
  87.      * @var boolean 
  88.      */
  89.     private $_formatRows;
  90.     
  91.     /**
  92.      * Insert columns
  93.      *
  94.      * @var boolean 
  95.      */
  96.     private $_insertColumns;
  97.     
  98.     /**
  99.      * Insert rows
  100.      *
  101.      * @var boolean 
  102.      */
  103.     private $_insertRows;
  104.     
  105.     /**
  106.      * Insert hyperlinks
  107.      *
  108.      * @var boolean 
  109.      */
  110.     private $_insertHyperlinks;
  111.     
  112.     /**
  113.      * Delete columns
  114.      *
  115.      * @var boolean 
  116.      */
  117.     private $_deleteColumns;
  118.     
  119.     /**
  120.      * Delete rows
  121.      *
  122.      * @var boolean 
  123.      */
  124.     private $_deleteRows;
  125.     
  126.     /**
  127.      * Select locked cells
  128.      *
  129.      * @var boolean 
  130.      */
  131.     private $_selectLockedCells;
  132.     
  133.     /**
  134.      * Sort
  135.      *
  136.      * @var boolean 
  137.      */
  138.     private $_sort;
  139.     
  140.     /**
  141.      * AutoFilter
  142.      *
  143.      * @var boolean 
  144.      */
  145.     private $_autoFilter;
  146.     
  147.     /**
  148.      * Pivot tables
  149.      *
  150.      * @var boolean 
  151.      */
  152.     private $_pivotTables;
  153.     
  154.     /**
  155.      * Select unlocked cells
  156.      *
  157.      * @var boolean 
  158.      */
  159.     private $_selectUnlockedCells;
  160.             
  161.     /**
  162.      * Password
  163.      *
  164.      * @var string 
  165.      */
  166.     private $_password;
  167.     
  168.     /**
  169.      * Create a new PHPExcel_Worksheet_Protection
  170.      */
  171.     public function __construct()
  172.     {
  173.         // Initialise values
  174.         $this->_sheet                    = false;
  175.         $this->_objects                    = false;
  176.         $this->_scenarios                = false;
  177.         $this->_formatCells                = false;
  178.         $this->_formatColumns            = false;
  179.         $this->_formatRows                = false;
  180.         $this->_insertColumns            = false;
  181.         $this->_insertRows                = false;
  182.         $this->_insertHyperlinks        = false;
  183.         $this->_deleteColumns            = false;
  184.         $this->_deleteRows                = false;
  185.         $this->_selectLockedCells        = false;
  186.         $this->_sort                    = false;
  187.         $this->_autoFilter                = false;
  188.         $this->_pivotTables                = false;
  189.         $this->_selectUnlockedCells        = false;
  190.         $this->_password                = '';
  191.     }
  192.  
  193.     /**
  194.      * Is some sort of protection enabled?
  195.      *
  196.      * @return boolean 
  197.      */
  198.     function isProtectionEnabled({
  199.         return     $this->_sheet ||
  200.                 $this->_objects ||
  201.                 $this->_scenarios ||
  202.                 $this->_formatCells ||
  203.                 $this->_formatColumns ||
  204.                 $this->_formatRows ||
  205.                 $this->_insertColumns ||
  206.                 $this->_insertRows ||
  207.                 $this->_insertHyperlinks ||
  208.                 $this->_deleteColumns ||
  209.                 $this->_deleteRows ||
  210.                 $this->_selectLockedCells ||
  211.                 $this->_sort ||
  212.                 $this->_autoFilter ||
  213.                 $this->_pivotTables ||
  214.                 $this->_selectUnlockedCells;
  215.     }
  216.     
  217.     /**
  218.      * Get Sheet
  219.      *
  220.      * @return boolean 
  221.      */
  222.     function getSheet({
  223.         return $this->_sheet;
  224.     }
  225.     
  226.     /**
  227.      * Set Sheet
  228.      *
  229.      * @param boolean $pValue 
  230.      * @return PHPExcel_Worksheet_Protection 
  231.      */
  232.     function setSheet($pValue false{
  233.         $this->_sheet = $pValue;
  234.         return $this;
  235.     }
  236.  
  237.     /**
  238.      * Get Objects
  239.      *
  240.      * @return boolean 
  241.      */
  242.     function getObjects({
  243.         return $this->_objects;
  244.     }
  245.     
  246.     /**
  247.      * Set Objects
  248.      *
  249.      * @param boolean $pValue 
  250.      * @return PHPExcel_Worksheet_Protection 
  251.      */
  252.     function setObjects($pValue false{
  253.         $this->_objects = $pValue;
  254.         return $this;
  255.     }
  256.  
  257.     /**
  258.      * Get Scenarios
  259.      *
  260.      * @return boolean 
  261.      */
  262.     function getScenarios({
  263.         return $this->_scenarios;
  264.     }
  265.     
  266.     /**
  267.      * Set Scenarios
  268.      *
  269.      * @param boolean $pValue 
  270.      * @return PHPExcel_Worksheet_Protection 
  271.      */
  272.     function setScenarios($pValue false{
  273.         $this->_scenarios = $pValue;
  274.         return $this;
  275.     }
  276.  
  277.     /**
  278.      * Get FormatCells
  279.      *
  280.      * @return boolean 
  281.      */
  282.     function getFormatCells({
  283.         return $this->_formatCells;
  284.     }
  285.     
  286.     /**
  287.      * Set FormatCells
  288.      *
  289.      * @param boolean $pValue 
  290.      * @return PHPExcel_Worksheet_Protection 
  291.      */
  292.     function setFormatCells($pValue false{
  293.         $this->_formatCells = $pValue;
  294.         return $this;
  295.     }
  296.  
  297.     /**
  298.      * Get FormatColumns
  299.      *
  300.      * @return boolean 
  301.      */
  302.     function getFormatColumns({
  303.         return $this->_formatColumns;
  304.     }
  305.     
  306.     /**
  307.      * Set FormatColumns
  308.      *
  309.      * @param boolean $pValue 
  310.      * @return PHPExcel_Worksheet_Protection 
  311.      */
  312.     function setFormatColumns($pValue false{
  313.         $this->_formatColumns = $pValue;
  314.         return $this;
  315.     }
  316.  
  317.     /**
  318.      * Get FormatRows
  319.      *
  320.      * @return boolean 
  321.      */
  322.     function getFormatRows({
  323.         return $this->_formatRows;
  324.     }
  325.     
  326.     /**
  327.      * Set FormatRows
  328.      *
  329.      * @param boolean $pValue 
  330.      * @return PHPExcel_Worksheet_Protection 
  331.      */
  332.     function setFormatRows($pValue false{
  333.         $this->_formatRows = $pValue;
  334.         return $this;
  335.     }
  336.  
  337.     /**
  338.      * Get InsertColumns
  339.      *
  340.      * @return boolean 
  341.      */
  342.     function getInsertColumns({
  343.         return $this->_insertColumns;
  344.     }
  345.     
  346.     /**
  347.      * Set InsertColumns
  348.      *
  349.      * @param boolean $pValue 
  350.      * @return PHPExcel_Worksheet_Protection 
  351.      */
  352.     function setInsertColumns($pValue false{
  353.         $this->_insertColumns = $pValue;
  354.         return $this;
  355.     }
  356.  
  357.     /**
  358.      * Get InsertRows
  359.      *
  360.      * @return boolean 
  361.      */
  362.     function getInsertRows({
  363.         return $this->_insertRows;
  364.     }
  365.     
  366.     /**
  367.      * Set InsertRows
  368.      *
  369.      * @param boolean $pValue 
  370.      * @return PHPExcel_Worksheet_Protection 
  371.      */
  372.     function setInsertRows($pValue false{
  373.         $this->_insertRows = $pValue;
  374.         return $this;
  375.     }
  376.  
  377.     /**
  378.      * Get InsertHyperlinks
  379.      *
  380.      * @return boolean 
  381.      */
  382.     function getInsertHyperlinks({
  383.         return $this->_insertHyperlinks;
  384.     }
  385.     
  386.     /**
  387.      * Set InsertHyperlinks
  388.      *
  389.      * @param boolean $pValue 
  390.      * @return PHPExcel_Worksheet_Protection 
  391.      */
  392.     function setInsertHyperlinks($pValue false{
  393.         $this->_insertHyperlinks = $pValue;
  394.         return $this;
  395.     }
  396.  
  397.     /**
  398.      * Get DeleteColumns
  399.      *
  400.      * @return boolean 
  401.      */
  402.     function getDeleteColumns({
  403.         return $this->_deleteColumns;
  404.     }
  405.     
  406.     /**
  407.      * Set DeleteColumns
  408.      *
  409.      * @param boolean $pValue 
  410.      * @return PHPExcel_Worksheet_Protection 
  411.      */
  412.     function setDeleteColumns($pValue false{
  413.         $this->_deleteColumns = $pValue;
  414.         return $this;
  415.     }
  416.  
  417.     /**
  418.      * Get DeleteRows
  419.      *
  420.      * @return boolean 
  421.      */
  422.     function getDeleteRows({
  423.         return $this->_deleteRows;
  424.     }
  425.     
  426.     /**
  427.      * Set DeleteRows
  428.      *
  429.      * @param boolean $pValue 
  430.      * @return PHPExcel_Worksheet_Protection 
  431.      */
  432.     function setDeleteRows($pValue false{
  433.         $this->_deleteRows = $pValue;
  434.         return $this;
  435.     }
  436.  
  437.     /**
  438.      * Get SelectLockedCells
  439.      *
  440.      * @return boolean 
  441.      */
  442.     function getSelectLockedCells({
  443.         return $this->_selectLockedCells;
  444.     }
  445.     
  446.     /**
  447.      * Set SelectLockedCells
  448.      *
  449.      * @param boolean $pValue 
  450.      * @return PHPExcel_Worksheet_Protection 
  451.      */
  452.     function setSelectLockedCells($pValue false{
  453.         $this->_selectLockedCells = $pValue;
  454.         return $this;
  455.     }
  456.  
  457.     /**
  458.      * Get Sort
  459.      *
  460.      * @return boolean 
  461.      */
  462.     function getSort({
  463.         return $this->_sort;
  464.     }
  465.     
  466.     /**
  467.      * Set Sort
  468.      *
  469.      * @param boolean $pValue 
  470.      * @return PHPExcel_Worksheet_Protection 
  471.      */
  472.     function setSort($pValue false{
  473.         $this->_sort = $pValue;
  474.         return $this;
  475.     }
  476.  
  477.     /**
  478.      * Get AutoFilter
  479.      *
  480.      * @return boolean 
  481.      */
  482.     function getAutoFilter({
  483.         return $this->_autoFilter;
  484.     }
  485.     
  486.     /**
  487.      * Set AutoFilter
  488.      *
  489.      * @param boolean $pValue 
  490.      * @return PHPExcel_Worksheet_Protection 
  491.      */
  492.     function setAutoFilter($pValue false{
  493.         $this->_autoFilter = $pValue;
  494.         return $this;
  495.     }
  496.  
  497.     /**
  498.      * Get PivotTables
  499.      *
  500.      * @return boolean 
  501.      */
  502.     function getPivotTables({
  503.         return $this->_pivotTables;
  504.     }
  505.     
  506.     /**
  507.      * Set PivotTables
  508.      *
  509.      * @param boolean $pValue 
  510.      * @return PHPExcel_Worksheet_Protection 
  511.      */
  512.     function setPivotTables($pValue false{
  513.         $this->_pivotTables = $pValue;
  514.         return $this;
  515.     }
  516.  
  517.     /**
  518.      * Get SelectUnlockedCells
  519.      *
  520.      * @return boolean 
  521.      */
  522.     function getSelectUnlockedCells({
  523.         return $this->_selectUnlockedCells;
  524.     }
  525.     
  526.     /**
  527.      * Set SelectUnlockedCells
  528.      *
  529.      * @param boolean $pValue 
  530.      * @return PHPExcel_Worksheet_Protection 
  531.      */
  532.     function setSelectUnlockedCells($pValue false{
  533.         $this->_selectUnlockedCells = $pValue;
  534.         return $this;
  535.     }
  536.     
  537.     /**
  538.      * Get Password (hashed)
  539.      *
  540.      * @return string 
  541.      */
  542.     function getPassword({
  543.         return $this->_password;
  544.     }
  545.  
  546.     /**
  547.      * Set Password
  548.      *
  549.      * @param string     $pValue 
  550.      * @param boolean     $pAlreadyHashed If the password has already been hashed, set this to true
  551.      * @return PHPExcel_Worksheet_Protection 
  552.      */
  553.     function setPassword($pValue ''$pAlreadyHashed false{
  554.         if (!$pAlreadyHashed{
  555.             $pValue PHPExcel_Shared_PasswordHasher::hashPassword($pValue);
  556.         }
  557.         $this->_password = $pValue;
  558.         return $this;
  559.     }
  560.  
  561.     /**
  562.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  563.      */
  564.     public function __clone({
  565.         $vars get_object_vars($this);
  566.         foreach ($vars as $key => $value{
  567.             if (is_object($value)) {
  568.                 $this->$key clone $value;
  569.             else {
  570.                 $this->$key $value;
  571.             }
  572.         }
  573.     }
  574. }

Documentation generated on Mon, 10 Aug 2009 08:07:26 +0200 by phpDocumentor 1.4.1