diff --git a/JS/happy.js b/JS/happy.js new file mode 100644 index 0000000..4f6a8b9 --- /dev/null +++ b/JS/happy.js @@ -0,0 +1,134 @@ +/*global $*/ +(function happyJS($) { + function trim(el) { + return (''.trim) ? el.val().trim() : $.trim(el.val()); + } + $.fn.isHappy = function isHappy(config) { + var fields = [], item; + var pauseMessages = false; + + function isFunction(obj) { + return !!(obj && obj.constructor && obj.call && obj.apply); + } + function defaultError(error) { //Default error template + var msgErrorClass = config.classes && config.classes.message || 'unhappyMessage'; + return $('' + error.message + ''); + } + function getError(error) { //Generate error html from either config or default + if (isFunction(config.errorTemplate)) { + return config.errorTemplate(error); + } + return defaultError(error); + } + function handleSubmit() { + var i, l; + var errors = false; + for (i = 0, l = fields.length; i < l; i += 1) { + if (!fields[i].testValid(true)) { + errors = true; + } + } + if (errors) { + if (isFunction(config.unHappy)) config.unHappy(); + return false; + } else if (config.testMode) { + if (isFunction(config.happy)) return config.happy(); + if (window.console) console.warn('would have submitted'); + return false; + } + if (isFunction(config.happy)) return config.happy(); + } + function handleMouseUp() { + pauseMessages = false; + } + function handleMouseDown() { + pauseMessages = true; + $(window).bind('mouseup', handleMouseUp); + } + function processField(opts, selector) { + var field = $(selector); + var error = { + message: opts.message || '', + id: selector.slice(1) + '_unhappy' + }; + var errorEl = $(error.id).length > 0 ? $(error.id) : getError(error); + var handleBlur = function handleBlur() { + if (!pauseMessages) { + field.testValid(); + } else { + $(window).bind('mouseup', field.testValid.bind(this)); + } + }; + + fields.push(field); + field.testValid = function testValid(submit) { + var val, gotFunc, temp; + var el = $(this); + var errorTarget = (opts.errorTarget && $(opts.errorTarget)) || el; + var error = false; + var required = !!el.get(0).attributes.getNamedItem('required') || opts.required; + var password = (field.attr('type') === 'password'); + var arg = isFunction(opts.arg) ? opts.arg() : opts.arg; + var fieldErrorClass = config.classes && config.classes.field || 'unhappy'; + + // handle control groups (checkboxes, radio) + if (el.length > 1) { + val = []; + el.each(function(i,obj) { + val.push($(obj).val()); + }); + val = val.join(','); + } else { + // clean it or trim it + if (isFunction(opts.clean)) { + val = opts.clean(el.val()); + } else if (!password && typeof opts.trim === 'undefined' || opts.trim) { + val = trim(el); + } else { + val = el.val(); + } + + // write it back to the field + el.val(val); + } + + // get the value + gotFunc = ((val.length > 0 || required === 'sometimes') && isFunction(opts.test)); + + // check if we've got an error on our hands + if (submit === true && required === true && val.length === 0) { + error = true; + } else if (gotFunc) { + error = !opts.test(val, arg); + } + + if (error) { + errorTarget.addClass(fieldErrorClass).after(errorEl); + return false; + } else { + temp = errorEl.get(0); + // this is for zepto + if (temp.parentNode) { + temp.parentNode.removeChild(temp); + } + errorTarget.removeClass(fieldErrorClass); + return true; + } + }; + field.bind(opts.when || config.when || 'blur', handleBlur); + } + + for (item in config.fields) { + processField(config.fields[item], item); + } + + $(config.submitButton || this).bind('mousedown', handleMouseDown); + + if (config.submitButton) { + $(config.submitButton).click(handleSubmit); + } else { + this.bind('submit', handleSubmit); + } + return this; + }; +})(this.jQuery || this.Zepto); \ No newline at end of file diff --git a/JS/lawmakers.js b/JS/lawmakers.js new file mode 100644 index 0000000..4e73e8c --- /dev/null +++ b/JS/lawmakers.js @@ -0,0 +1 @@ +$('.legislators_main').shapeshift(); \ No newline at end of file diff --git a/JS/loginval.js b/JS/loginval.js new file mode 100644 index 0000000..b85e703 --- /dev/null +++ b/JS/loginval.js @@ -0,0 +1,16 @@ +$(document).ready(function () { + $('#loginform').isHappy({ + fields: { + // reference the field you're talking about, probably by `id` + // but you could certainly do $('[name=name]') as well. + '#username': { + required: true, + message: 'Might we inquire your name' + }, + '#password': { + required: true, + message: 'Dont forget your password' + } + } + }); + }); \ No newline at end of file diff --git a/JS/shapeshift.min.js b/JS/shapeshift.min.js new file mode 100644 index 0000000..cc66246 --- /dev/null +++ b/JS/shapeshift.min.js @@ -0,0 +1 @@ +(function(){(function(e,c,a){var b,f,d;d="shapeshift";f={selector:"*",enableDrag:true,enableCrossDrop:true,enableResize:true,enableTrash:false,align:"center",colWidth:null,columns:null,minColumns:1,autoHeight:true,maxHeight:null,minHeight:100,gutterX:10,gutterY:10,paddingX:10,paddingY:10,animated:true,animateOnInit:false,animationSpeed:225,animationThreshold:100,dragClone:false,deleteClone:true,dragRate:100,dragWhitelist:"*",crossDropWhitelist:"*",cutoffStart:null,cutoffEnd:null,handle:false,cloneClass:"ss-cloned-child",activeClass:"ss-active-child",draggedClass:"ss-dragged-child",placeholderClass:"ss-placeholder-child",originalContainerClass:"ss-original-container",currentContainerClass:"ss-current-container",previousContainerClass:"ss-previous-container"};b=(function(){function g(i,h){this.element=i;this.options=e.extend({},f,h);this.globals={};this.$container=e(i);if(this.errorCheck()){this.init()}}g.prototype.errorCheck=function(){var h,j,k,i;i=this.options;k=false;j="Shapeshift ERROR:";if(i.colWidth===null){h=this.$container.children(i.selector);if(h.length===0){k=true;console.error(""+j+" option colWidth must be specified if Shapeshift is initialized with no active children.")}}return !k};g.prototype.init=function(){this.createEvents();this.setGlobals();this.setIdentifier();this.setActiveChildren();this.enableFeatures();this.gridInit();this.render();return this.afterInit()};g.prototype.createEvents=function(){var i,h,j=this;h=this.options;i=this.$container;i.off("ss-arrange").on("ss-arrange",function(l,k){if(k==null){k=false}return j.render(false,k)});i.off("ss-rearrange").on("ss-rearrange",function(){return j.render(true)});i.off("ss-setTargetPosition").on("ss-setTargetPosition",function(){return j.setTargetPosition()});i.off("ss-destroy").on("ss-destroy",function(){return j.destroy()});return i.off("ss-shuffle").on("ss-shuffle",function(){return j.shuffle()})};g.prototype.setGlobals=function(){this.globals.animated=this.options.animateOnInit;return this.globals.dragging=false};g.prototype.afterInit=function(){return this.globals.animated=this.options.animated};g.prototype.setIdentifier=function(){this.identifier="shapeshifted_container_"+Math.random().toString(36).substring(7);return this.$container.addClass(this.identifier)};g.prototype.enableFeatures=function(){if(this.options.enableResize){this.enableResize()}if(this.options.enableDrag||this.options.enableCrossDrop){return this.enableDragNDrop()}};g.prototype.setActiveChildren=function(){var s,p,h,j,o,q,t,r,m,l,n,k;t=this.options;s=this.$container.children(t.selector);p=t.activeClass;r=s.length;for(o=m=0;0<=r?mr;o=0<=r?++m:--m){e(s[o]).addClass(p)}this.setParsedChildren();j=t.columns;k=[];for(o=l=0,n=this.parsedChildren.length;0<=n?ln;o=0<=n?++l:--l){h=this.parsedChildren[o].colspan;q=t.minColumns;if(h>j&&h>q){t.minColumns=h;k.push(console.error("Shapeshift ERROR: There are child elements that have a larger colspan than the minimum columns set through options.\noptions.minColumns has been set to "+h))}else{k.push(void 0)}}return k};g.prototype.setParsedChildren=function(){var m,h,o,j,n,k,l;h=this.$container.find("."+this.options.activeClass).filter(":visible");k=h.length;n=[];for(j=l=0;0<=k?lk;j=0<=k?++l:--l){m=e(h[j]);o={i:j,el:m,colspan:parseInt(m.attr("data-ss-colspan"))||1,height:m.outerHeight()};n.push(o)}return this.parsedChildren=n};g.prototype.gridInit=function(){var i,h,k,j,l;j=this.options.gutterX;if(!(this.options.colWidth>=1)){k=this.parsedChildren[0];h=k.el.outerWidth();i=k.colspan;l=(h-((i-1)*j))/i;return this.globals.col_width=l+j}else{return this.globals.col_width=this.options.colWidth+j}};g.prototype.render=function(i,h){if(i==null){i=false}this.setGridColumns();return this.arrange(i,h)};g.prototype.setGridColumns=function(){var s,v,u,j,l,q,k,t,p,h,r,w,m,n,o;q=this.globals;w=this.options;u=q.col_width;t=w.gutterX;m=w.paddingX;h=this.$container.innerWidth()-(m*2);r=w.minColumns;l=w.columns||Math.floor((h+t)/u);if(r&&r>l){l=r}q.columns=l;v=this.parsedChildren.length;if(l>v){s=0;for(p=n=0,o=this.parsedChildren.length;0<=o?no;p=0<=o?++n:--n){j=this.parsedChildren[p].colspan;if(j+s<=l){s+=j}}l=s}q.child_offset=m;switch(w.align){case"center":k=(l*u)-t;return q.child_offset+=(h-k)/2;case"right":k=(l*u)-t;return q.child_offset+=h-k}};g.prototype.arrange=function(m,y){var z,v,x,h,r,o,s,q,n,w,j,u,B,p,A,t,l,k;if(m){this.setParsedChildren()}n=this.globals;p=this.options;v=this.$container;o=this.getPositions();A=this.parsedChildren;l=A.length;x=n.animated&&l<=p.animationThreshold;h=p.animationSpeed;q=p.draggedClass;for(w=k=0;0<=l?kl;w=0<=l?++k:--k){z=A[w].el;r=o[w];j=z.hasClass(q);if(j){t=p.placeholderClass;z=z.siblings("."+t)}if(x&&!j){z.stop(true,false).animate(r,h,function(){})}else{z.css(r)}}if(y){if(x){setTimeout((function(){return v.trigger("ss-drop-complete")}),h)}else{v.trigger("ss-drop-complete")}}v.trigger("ss-arranged");if(p.autoHeight){s=n.container_height;u=p.maxHeight;B=p.minHeight;if(B&&su){s=u}}return v.height(s)}};g.prototype.getPositions=function(v){var n,y,q,o,l,z,h,w,m,t,B,p,A,x,s,k,j,r,u=this;if(v==null){v=true}l=this.globals;m=this.options;h=m.gutterY;t=m.paddingY;o=m.draggedClass;B=this.parsedChildren;k=B.length;n=[];for(w=j=0,r=l.columns;0<=r?jr;w=0<=r?++j:--j){n.push(t)}x=function(I){var D,H,C,G,E,F,i;D=I.col;H=I.colspan;G=(I.col*l.col_width)+l.child_offset;E=n[D];p[I.i]={left:G,top:E};n[D]+=I.height+h;if(H>=1){i=[];for(C=F=1;1<=H?FH;C=1<=H?++F:--F){i.push(n[D+C]=n[D])}return i}};y=function(i){var N,E,C,M,I,D,H,L,J,K,G,F;J=n.length-i.colspan+1;L=n.slice(0).splice(0,J);N=void 0;for(H=G=0;0<=J?GJ;H=0<=J?++G:--G){E=u.lowestCol(L,H);C=i.colspan;M=n[E];I=true;for(K=F=1;1<=C?FC;K=1<=C?++F:--F){D=n[E+K];if(MH;I=0<=H?++G:--G){E=s[I];E.col=y(E);if(E.col>=0){x(E);K.push(I)}}F=[];for(i=D=C=K.length-1;D>=0;i=D+=-1){J=K[i];F.push(s.splice(J,1))}return F};p=[];(q=function(){var D,C,i;i=[];for(w=C=0;0<=k?Ck;w=0<=k?++C:--C){D=B[w];if(!(!v&&D.el.hasClass(o))){if(D.colspan>1){D.col=y(D)}else{D.col=u.lowestCol(n)}if(D.col===void 0){s.push(D)}else{x(D)}i.push(A())}else{i.push(void 0)}}return i})();if(m.autoHeight){z=n[this.highestCol(n)]-h;l.container_height=z+t}return p};g.prototype.enableDragNDrop=function(){var p,v,n,y,l,t,o,w,q,z,s,m,j,x,r,k,i,h,u=this;j=this.options;v=this.$container;l=j.activeClass;m=j.draggedClass;r=j.placeholderClass;x=j.originalContainerClass;o=j.currentContainerClass;k=j.previousContainerClass;w=j.deleteClone;z=j.dragRate;q=j.dragClone;t=j.cloneClass;y=n=p=h=i=null;s=false;if(j.enableDrag){v.children("."+l).filter(j.dragWhitelist).draggable({addClasses:false,containment:"document",handle:j.handle,zIndex:9999,start:function(C,B){var A;u.globals.dragging=true;y=e(C.target);if(q){p=y.clone(false,false).insertBefore(y).addClass(t)}y.addClass(m);A=y.prop("tagName");n=e("<"+A+" class='"+r+"' style='height: "+(y.height())+"px; width: "+(y.width())+"px'>");y.parent().addClass(x).addClass(o);h=y.outerHeight()/2;return i=y.outerWidth()/2},drag:function(B,A){if(!s&&!(q&&w&&e("."+o)[0]===e("."+x)[0])){n.remove().appendTo("."+o);e("."+o).trigger("ss-setTargetPosition");s=true;c.setTimeout((function(){return s=false}),z)}A.position.left=B.pageX-y.parent().offset().left-i;return A.position.top=B.pageY-y.parent().offset().top-h},stop:function(){var A,C,B;u.globals.dragging=false;C=e("."+x);A=e("."+o);B=e("."+k);y.removeClass(m);e("."+r).remove();if(q){if(w&&e("."+o)[0]===e("."+x)[0]){p.remove();e("."+o).trigger("ss-rearrange")}else{p.removeClass(t)}}if(C[0]===A[0]){A.trigger("ss-rearranged",y)}else{C.trigger("ss-removed",y);A.trigger("ss-added",y)}C.trigger("ss-arrange").removeClass(x);A.trigger("ss-arrange",true).removeClass(o);B.trigger("ss-arrange").removeClass(k);return y=n=null}})}if(j.enableCrossDrop){return v.droppable({accept:j.crossDropWhitelist,tolerance:"intersect",over:function(A){e("."+k).removeClass(k);e("."+o).removeClass(o).addClass(k);return e(A.target).addClass(o)},drop:function(E,B){var A,D,C;if(u.options.enableTrash){D=e("."+x);A=e("."+o);C=e("."+k);y=e(B.helper);A.trigger("ss-trashed",y);y.remove();D.trigger("ss-rearrange").removeClass(x);A.trigger("ss-rearrange").removeClass(o);return C.trigger("ss-arrange").removeClass(k)}}})}};g.prototype.setTargetPosition=function(){var C,A,k,t,j,y,u,n,p,m,B,w,z,o,s,q,r,v,x,h,l,i;m=this.options;if(!m.enableTrash){p=m.draggedClass;C=e("."+p);A=C.parent();B=this.parsedChildren;j=this.getPositions(false);x=j.length;s=C.offset().left-A.offset().left+(this.globals.col_width/2);q=C.offset().top-A.offset().top+(C.height()/2);r=9999999;v=0;if(x>1){u=m.cutoffStart+1||0;y=m.cutoffEnd||x;for(z=i=u;u<=y?iy;z=u<=y?++i:--i){t=j[z];if(t){l=s-t.left;h=q-t.top;if(l>0&&h>0){n=Math.sqrt((h*h)+(l*l));if(nB[z].height/2){v++}}}}}}if(v===B.length){k=B[v-1].el;C.insertAfter(k)}else{k=B[v].el;C.insertBefore(k)}}else{if(x===1){t=j[0];if(t.leftk;j=0<=k?++l:--l){h.push([n[j],j])}h.sort(function(o,i){var p;p=o[0]-i[0];if(p===0){p=o[1]-i[1]}return p});return h[m][1]};g.prototype.highestCol=function(h){return e.inArray(Math.max.apply(c,h),h)};g.prototype.destroy=function(){var h,j,i;j=this.$container;j.off("ss-arrange");j.off("ss-rearrange");j.off("ss-setTargetPosition");j.off("ss-destroy");i=this.options.activeClass;h=j.find("."+i);if(this.options.enableDrag){h.draggable("destroy")}if(this.options.enableCrossDrop){j.droppable("destroy")}h.removeClass(i);return j.removeClass(this.identifier)};return g})();return e.fn[d]=function(g){return this.each(function(){var k,i,j,h;i=(j=e(this).attr("class"))!=null?(h=j.match(/shapeshifted_container_\w+/))!=null?h[0]:void 0:void 0;if(i){k="resize."+i;e(c).off(k);e(this).removeClass(i)}return e.data(this,"plugin_"+d,new b(this,g))})}})(jQuery,window,document)}).call(this); \ No newline at end of file diff --git a/css/styles.css b/css/styles.css new file mode 100644 index 0000000..c70e2f8 --- /dev/null +++ b/css/styles.css @@ -0,0 +1,401 @@ +.tops { + width: 100%; + height: 125px; + background-image: url("../images/topo.png"); + background-repeat: repeat; + float: left; + } + +#topline { + width: 100%; + height: 40px; + background-color: #99cccc; + opacity: 0.4; + float: left; + } + + +div.socials { + margin: 0; + position: absolute; + top: 0; + right: 0; + text-align: right; + font-size: 1.2em; + padding: 1.25em .5em; + } + +.socials ul { + list-style: none; + } + +.socials li { + position: relative; + display: inline-block; + margin-right: .125em; + } + +li.social_tw a { + text-decoration: none; + background-image: url("../images/twittericon.png"); + } + +#logoline { + width: 100%; + height: 45px; + float: left; + } + +div#logo { + float: left; + font-family: Garamond, "Times New Roman", serif; + font-size: 24px; + } + + + +#slogan { + float: left; + font-family: Garamond, "Times New Roman", serif; + font-size: 16px + padding: 40 + } + +#menu { + width: 100%; + height: 40px; + background-color: #99cccc; + opacity: 0.4; + clear: both; + float: left; + } + +#menu ul { + list-style: none; + margin: 0; + padding: 0; + overflow: hidden; +} + +#menu li { + float: left; + display: inline-block + padding: .5em; + margin: 10; + } + +body { + font-family: 'Source Sans Pro', Helvetica, sans-serif; + font-size: 12px; + line-height: 1.3rem; + font-weight: 400; + margin: 0; + padding: 0; +} +.tops { + width: 100%; + height: 100%; + background-image: url("../images/topo.png"); + background-repeat: repeat; + float: left; +} +#topline { + width: 100%; + height: 100%; + padding: 10px; + background-color: rgba(153, 204, 204, .4); + float: left; +} +div.socials { + margin: 0; + position: absolute; + top: 0px; + right: 5px; +} +.socials ul { + list-style: none; +} +.socials li { + position: relative; + display: inline; + margin-right: .125em; +} +.socials li a { + text-decoration: none; +} +#logoline { + width: 100%; + height: 100%; + float: left; +} +#logo { + float: left; + letter-spacing: .15em; + font-family: Garamond, "Times New Roman", serif; + font-size: 1.5rem; + padding: 0px 10px 0px 0px; +} +#slogan { + float: left; + font-family: "Trebuchet MS", Helvetica, sans-serif; + font-size: .7rem; + padding: 25px 0px 0px 0px; +} +#menu { + width: 100%; + height: 100%; + background-color: rgba(153, 204, 204, .4); + float: left; +} +#menu ul { + list-style: none; + margin: 5px 35px; + padding: 1px 10px; + overflow: hidden; +} +#menu li { + display: inline-block; + padding: 1px; + margin: 1px 10px; + font-size: 1rem; + font-family: "Trebuchet MS", Helvetica, sans-serif; + text-transform: uppercase; +} +#menu a { + text-decoration: none; + color: black; +} +#menu a:hover { + color: gray; +} +#menu #currentpage { + text-decoration: underline; +} +.maincontainer { + clear: both; + width: 100%; +} +.dashboard { + width: 20%; + height: 100%; + float: left; + background-color: #EFF0F2; + padding: 0px; + margin-top: 10px; + border-right: solid 1px black; + border-bottom: solid 1px black; +} +.dashhead { + text-align: center; + color: white; + font-size: 1.2rem; + text-transform: uppercase; + padding: 20px 0px 10px 0px; +} +.dashitem { + color: #3F5388; + padding: 10px; + line-height: 1em; +} +form { + width: 100%; + margin: 0px; +} +input[type=submit] { + float: right; + position: relative; + padding: 7px 15px; + left: 0px; + border: 2px solid #207cca; + background-color: #207cca; + color: white; +} +input[type=search], +input[type=email], +input[type=text], +input[type=password], +textarea { + width: 100%; + padding: 8px 15px; + background: rgba(239, 240, 242, 0.4); + /* border: 1px solid black; */ +} +div { + overflow: hidden; + padding-right: 0em; +} +#newuser { + text-align: right; + color: #3F5388; + padding: 10px; + line-height: 1em; + margin: 0px 10px; + text-transform: uppercase; +} +#newuser a { + text-decoration: none; +} +#dashtop { + background-color: #333C45; +} +#login { + background-color: #ECC64B; +} +label[for="rememberme"] { + margin: 0px 20px; +} +#bills { + background-color: #99CCCC; +} +#testimony { + background-color: #0A9DA5; +} +#lawmakers { + background-color: #364F8A; +} +#topics { + background-color: #8CAC8C; +} +.billmain { + width: 79%; + height: 100%; + background-color: white; + float: left; + margin: 0px; + position: relative; +} + +.active { + border: 1px solid black; + padding: 0px 10px; + margin: 10px 0px 5px 10px; + background-color: #EFF0F2; +} +.active p { + font-size: 1.3rem; + text-transform: uppercase; + font-style: italic; +} +.billimage { + background-image: url("../images/billpage.png"); + position: relative; + width: 70px; + height: 70px; + float: left; + margin: 0px 5px 0px 0px; + border: 1px solid gray; +} +.billimage span { + font-size: 1.5em; + font-family: 'Source Sans Pro', Helvetica, sans-serif; + font-weight: bold; + line-height: 70px; + padding: 0px 5px; + text-align: center; +} +.lastaction { + padding: 0px 0px 5px 0px; + font-style: italic; +} +.billsummary { + font-size: 1rem; + line-height: 1.1rem; +} +.legislators_main { + position: relative; + width: 100%; +} +.legislators_main div { + height: 50px; + position: absolute; + width: 50px; + border: 1px solid; +} +.comments { + border-top: 1px gray solid; + width: 100%; + height: 100%; + padding: 5px 0px 5px 5px; +} +.pro h3, .neutral h3, .anti h3 { + color: black; + text-transform: uppercase; + font-size: 1.2em; + line-height: 1.5em; + text-align: center; +} +.pro { + float: left; + width: 32%; + border-right: 1px dashed black; + padding-right: 5px; + min-height: 1px; + line-height: 1.2em; +} +.neutral { + float: left; + width: 32%; + border-right: 1px dashed black; + padding-left: 5px; + padding-right: 5px; + min-height: 1px; + line-height: 1.2em; +} +.anti { + float: left; + width: 31%; + padding-left: 5px; + min-height: 1px; + line-height: 1.2em; +} +.commentbox input[type=radio] { + margin: 0px 5px 0px 0px; + display: inline-block; + width: 20px; + height: 25px; +} +.commentbox label { + width: auto; + height: auto; + float: left; + margin: 0px 10px 10px 0px; + font-size: 1.8em; + text-align: center; + line-height: 20px; + vertical-align: baseline; +} +.comments span { + color: blue; + text-transform: uppercase; + font-size: 1.2em; + line-height: 1.5em; +} +.prolabel { + background-size: 20px; + width: 20px; + height: 25px; + background-repeat: no-repeat; + position: relative; +} +.antilabel { + width: 20px; + height: 25px; + background-size: 20px; + background-repeat: no-repeat; + position: relative; +} +.footer { + width: 100%; + height: 100%x; + background-image: url("../images/topo.png"); + background-repeat: repeat; + background-color: #F5FDE3; + clear: both; +} +#cc { + padding: 10px; + float: left; + vertical-align: top; + width: 40%; + line-height: 1rem; +} diff --git a/lib/api_functions.php b/lib/api_functions.php new file mode 100644 index 0000000..3f35bd6 --- /dev/null +++ b/lib/api_functions.php @@ -0,0 +1,17 @@ + \ No newline at end of file diff --git a/lib/classes/api_getter.php b/lib/classes/api_getter.php new file mode 100644 index 0000000..af2be27 --- /dev/null +++ b/lib/classes/api_getter.php @@ -0,0 +1,21 @@ +url_base + $key = $this->api_key + $url = $url_base . 'bills/' . $bill_id . $key; + $bill_json = file_get_contents($url); + $bill_detail = json_decode($bill_json, true); + return $bill_detail[action_dates][last]; +} + +} +?> \ No newline at end of file diff --git a/lib/classes/dao.php b/lib/classes/dao.php new file mode 100644 index 0000000..88bdf21 --- /dev/null +++ b/lib/classes/dao.php @@ -0,0 +1,111 @@ +dbhost};dbname={$this->database};port={$this->dbport}", $this->user, $this->password); + } + + public function check_login($name, $password) { + $conn = $this->getConnection(); + $name = $conn->quote($name); + $rows = $conn->query("SELECT password FROM users WHERE username = $name"); + if ($rows) { + foreach ($rows as $row) { #only one row should match + if ($password === $row["password"]) { + return TRUE; + } + } + } + return FALSE; # user not found, or wrong password + } + + public function ensure_logged_in() { + if (!isset($_SESSION[$name])) { + redirect("index.php", "You must login first"); + } + } + + public function redirect($url, $flash_message = NULL) { + if ($flash_message) { + $_SESSION["flash"] = $flash_message; + } + header("Location: $url"); + die; + } + + public function saveComment ($username, $comment, $bill, $comment_type) { + $conn = $this->getConnection(); + $saveQuery = + "INSERT INTO comments + (username, comment, bill_id, comment_type) + VALUES + (:username, :comment, :bill, :comment_type)"; + $q = $conn->prepare($saveQuery); + $q->bindParam(":username", $username); + $q->bindParam(":comment", $comment); + $q->bindParam(":bill", $bill); + $q->bindParam(":comment_type", $comment_type); + return $q->execute(); + } + + public function getComments ($bill, $comment_type) { + $conn = $this->getConnection(); + return $conn->query("SELECT username, comment, date FROM comments WHERE bill_id = '$bill' AND comment_type = '$comment_type'"); + } + + public function newUser ($username, $password, $email) { + $conn = $this->getConnection(); + $saveQuery = + "INSERT INTO users + (username, password, email) + VALUES + (:username, :password, :email)"; + $q = $conn->prepare($saveQuery); + $q->bindParam(":username", $username); + $q->bindParam(":password", $password); + $q->bindParam(":email", $email); + return $q->execute(); + } + + public function saveBills ($bill_id, $year, $title, $bill_name, $connection) { + + $saveQuery = + "INSERT INTO bills + (bill_id, year, title, bill_name) + VALUES + (:bill_id, :year, :title, :bill_name)"; + $q = $connection->prepare($saveQuery); + $q->bindParam(":bill_id", $bill_id); + $q->bindParam(":year", $year); + $q->bindParam(":title", $title); + $q->bindParam(":bill_name", $bill_name); + $q->execute(); + return $bill_name; + } + + public function getBills () { + $conn = $this->getConnection(); + return $conn->query("SELECT bill_name, bill_id, title, (votes_for + votes_against) AS total + FROM bills + ORDER BY total + LIMIT 5"); + } + + public function getLegislators () { + $conn = $this->getConnection(); + return $conn->query("SELECT first_name, last_name, middle_name, district, party, chamber, photo_url + FROM legislators"); + } + +} // end Dao +?> \ No newline at end of file diff --git a/lib/cron_functions.php b/lib/cron_functions.php new file mode 100644 index 0000000..58844ac --- /dev/null +++ b/lib/cron_functions.php @@ -0,0 +1,64 @@ +" . print_r($legislators, 1) . ""; + + $dao = new Dao(); + $connection = $dao->getConnection(); + $i = 1; + foreach ($legislators as $legislator) { + $sql = "INSERT INTO lawmakers(leg_id, last_name, first_name, middle_name, district, party, active, chamber, photo_url) + VALUES('" . $legislator['leg_id'] . "', " . + "'" . $legislator['last_name'] . "', " . + "'" . $legislator['first_name'] . "', " . + "'" . $legislator['middle_name'] . "', " . + $legislator['district'] . ", " . + "'" . $legislator['party'] . "', " . + $legislator['active'] . ", " . + "'" . $legislator['chamber'] . "', " . + "'" . $legislator['photo_url'] . "')"; + echo "inserting record $i
"; + $i++; + + $count = $connection->exec($sql) or die(print_r($connection->errorInfo(), true)); + echo "rows actually inserted $count
"; + } + + /* Save new bill information to bills table */ + + /* read the json file contents */ + + $jsondata = file_get_contents('http://openstates.org/api/v1/bills/?apikey=bcc2a830883c4f459dbffe94b2a3e90f&state=id&search_window=session'); + +//convert json object to php associative array + $bills = json_decode($jsondata, true); + + // echo "
" . print_r($bills, 1) . "
"; + + $dao = new Dao(); + $connection = $dao->getConnection(); + $i = 1; + foreach ($bills as $bill) { + $bill_name = $bill['bill_id']; + $year = $bill['session']; + $title = $bill['title']; + $bill_id = $bill['id']; + + echo "inserting record $i
"; + $i++; + + $dao->saveBills($bill_id, $year, $title, $bill_name, $connection) or die(print_r($connection->errorInfo(), true)); + echo "$bill_name actually inserted
"; + } + + + ?> \ No newline at end of file diff --git a/lib/etc/README.md b/lib/etc/README.md new file mode 100644 index 0000000..9e9a4fd --- /dev/null +++ b/lib/etc/README.md @@ -0,0 +1,2 @@ +# idleg +Interactive Portal to Idaho Legislature - Under Construction diff --git a/lib/etc/nhoffman.sql b/lib/etc/nhoffman.sql new file mode 100644 index 0000000..b792ed9 --- /dev/null +++ b/lib/etc/nhoffman.sql @@ -0,0 +1,91 @@ +CREATE TABLE IF NOT EXISTS users ( +email VARCHAR(256) NOT NULL, +username VARCHAR(64) NOT NULL PRIMARY KEY, +password VARCHAR(64) NOT NULL, +firstname VARCHAR(64), +lastname VARCHAR(64), +party VARCHAR(12), +website VARCHAR(64), +district_cong TINYINT, +district_leg TINYINT, +registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +verified BOOL +); + +CREATE TABLE IF NOT EXISTS comments ( +comment_id BIGINT(20) NOT NULL PRIMARY KEY AUTO_INCREMENT, +username VARCHAR(64), +comment MEDIUMBLOB, +comment_link VARCHAR(200), +comment_type VARCHAR(9), +votes_for TINYINT, +votes_against TINYINT, +flags TINYINT, +bill_id VARCHAR(20), +comment_ip VARCHAR(100), +comment TIMESTAMP DEFAULT CURRENT_TIMESTAMP, +comment_parent BIGINT(20), +approved BOOL +); + +CREATE TABLE IF NOT EXISTS topics ( +topic_id BIGINT(20) NOT NULL PRIMARY KEY AUTO_INCREMENT, +topic VARCHAR(64) +); + +CREATE TABLE IF NOT EXISTS bills_topics ( +bill_id BIGINT(20), +topic_id BIGINT(20) +); + +CREATE TABLE IF NOT EXISTS bills ( +bill_id VARCHAR(15) NOT NULL PRIMARY KEY, +year YEAR(4), +title MEDIUMBLOB, +bill_name VARCHAR(6), +votes_for BIGINT(20), +votes_against BIGINT(20) +); + +CREATE TABLE IF NOT EXISTS lawmakers ( +leg_id VARCHAR(9) NOT NULL PRIMARY KEY, +first_name VARCHAR(32) NOT NULL, +last_name VARCHAR(32) NOT NULL, +middle_name VARCHAR(32), +suffix VARCHAR(8), +nickname VARCHAR(32), +district INT(2), +twitter VARCHAR(64), +facebook VARCHAR(64), +website VARCHAR(64), +party VARCHAR(24), +active BOOL, +chamber VARCHAR(12), +photo_url VARCHAR(64) +); + +CREATE TABLE IF NOT EXISTS leg_geo ( +district INT(2) PRIMARY KEY, +polygon POLYGON NOT NULL +); + +CREATE TABLE IF NOT EXISTS user_bills ( +bill_id BIGINT(20), +user_id VARCHAR(64) +); + +CREATE TABLE IF NOT EXISTS user_friends ( +user_id VARCHAR(64), +friend_id VARCHAR(64) +); + +CREATE TABLE IF NOT EXISTS user_topics ( +user_id VARCHAR(64), +topic_id BIGINT(20) +); + +CREATE TABLE IF NOT EXISTS user_lawmakers ( +user_id VARCHAR(64), +lawmaker VARCHAR(9) +); + diff --git a/lib/functions.php b/lib/functions.php new file mode 100644 index 0000000..7a517ab --- /dev/null +++ b/lib/functions.php @@ -0,0 +1,93 @@ +prepare('SELECT * from users where username = "paleomedia"'); +$query->execute(); +?> +
+fetch(PDO::FETCH_ASSOC)){
+     var_dump($rows); } ?>
+     
+ +connect_error) { + die("Connection failed: " . $db->connect_error); + } + echo "Connected successfully (".$db->host_info.")"; + + +$db = new PDO("mysql:host=127.0.0.1;port=8889;dbname=idleg_test", "root", "root"); + var_dump($db); + + if ($db->connect_error) { + die("Connection failed: " . $db->connect_error); + } + echo "Connected successfully (".$db->host_info.")"; + +?> + + + + +/* read the json file contents */ + +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + +} catch (PDOException $ex) { + print "Error!: " . $ex->getMessage() . "
"; + die(); +} + +//insert into mysql table + mysql_select_db("lawmakers", $cxn); + $sql = "INSERT INTO lawmakers(first_name, last_name, middle_name, district, party, active, chamber, photo_url) + VALUES('$first_name', '$last_name', '$middle_name', '$district', '$party', '$active', '$chamber', '$photo_url')"; + if(!mysql_query($sql,$con)) + { + die('Error : ' . mysql_error()); + } + } + +?> \ No newline at end of file diff --git a/lib/granted.php b/lib/granted.php new file mode 100644 index 0000000..6169482 --- /dev/null +++ b/lib/granted.php @@ -0,0 +1,14 @@ + + +Logout \ No newline at end of file diff --git a/lib/handler.php b/lib/handler.php new file mode 100644 index 0000000..ceca7ef --- /dev/null +++ b/lib/handler.php @@ -0,0 +1,31 @@ +saveComment($username, $comment, $bill, $comment_type); + } + catch (Exception $e) { + var_dump($e); + die; + } + } + else { + $dao = new Dao(); + $dao -> redirect("../index.php", "Please log in to comment."); + } + + header("Location:../index.php"); \ No newline at end of file diff --git a/lib/login.php b/lib/login.php new file mode 100644 index 0000000..9eed8d2 --- /dev/null +++ b/lib/login.php @@ -0,0 +1,34 @@ + check_login($name, $password)) { + $_SESSION["name"] = $name; + + if ($_POST['rememberme']=1) { + $expireTime = time() + 60*60*24*180; # 180 days from now + setcookie("username", $_SESSION["name"], $expireTime); } + + $dao -> redirect("../index.php", "Login successful! Welcome back, $name."); + } + else { + $dao -> redirect("../index.php", "Incorrect user name and/or password."); + } + } + catch (Exception $e) { + var_dump($e); + die; + } +} + +?> \ No newline at end of file diff --git a/lib/logout.php b/lib/logout.php new file mode 100644 index 0000000..811c895 --- /dev/null +++ b/lib/logout.php @@ -0,0 +1,21 @@ + \ No newline at end of file diff --git a/lib/newuser.php b/lib/newuser.php new file mode 100644 index 0000000..41651b7 --- /dev/null +++ b/lib/newuser.php @@ -0,0 +1,37 @@ + newUser($username, $password, $email)) { + $_SESSION["name"] = $username; + + if (isset($_POST['rememberme']) && $_POST['rememberme']) { + $expireTime = time() + 60*60*24*180; # 180 days from now + setcookie("username", $_SESSION["name"], $expireTime); } + + $dao -> redirect("../index.php", "Welcome to idleg, $username!"); + + + } + else { + $dao -> redirect("../index.php", "User setup failed."); + } + } + catch (Exception $e) { + var_dump($e); + die; + } +} + +?> \ No newline at end of file diff --git a/lib/session_start.php b/lib/session_start.php new file mode 100644 index 0000000..c00731e --- /dev/null +++ b/lib/session_start.php @@ -0,0 +1,24 @@ + +
+ \ No newline at end of file diff --git a/lib/sql_logins.php b/lib/sql_logins.php new file mode 100644 index 0000000..770f8fc --- /dev/null +++ b/lib/sql_logins.php @@ -0,0 +1,27 @@ +